安装Stata 在R中调用Stata 三种环境下数据互通 安装Stata 首先安装ncurses5-compat-libs和libpng12这两个包
Use Color Palette Layer Color and Text Together Themes Use Theme Elements Two y-axes head(asasec) ## Section Sname Beginning Revenues ## 1 Aging and the Life Course (018) Aging 12752 12104 ## 2 Alcohol, Drugs and Tobacco (030) Alcohol/Drugs 11933 1144 ## 3 Altruism and Social Solidarity (047) Altruism 1139 1862 ## 4 Animals and Society (042) Animals 473 820 ## 5 Asia/Asian America (024) Asia 9056 2116 ## 6 Body and Embodiment (048) Body 3408 1618 ## Expenses Ending Journal Year Members ## 1 12007 12849 No 2005 598 ## 2 400 12677 No 2005 301 ## 3 1875 1126 No 2005 NA ## 4 1116 177 No 2005 209 ## 5 1710 9462 No 2005 365 ## 6 1920 3106 No 2005 NA p <- ggplot( data = subset(asasec, Year == 2014), mapping = aes(x = Members, y = Revenues, label = Sname) ) p + geom_point() + geom_smooth() p <- ggplot( data = subset(asasec, Year == 2014), mapping = aes(x = Members, y = Revenues, label = Sname) ) p + geom_point(mapping = aes(color = Journal)) + geom_smooth(method = "lm") p0 <- ggplot( data = subset(asasec, Year == 2014), mapping = aes(x = Members, y = Revenues, label = Sname) ) p1 <- p0 + geom_smooth(method = "lm", se = FALSE, color = "gray80") + geom_point(mapping = aes(color = Journal)) library(ggrepel) p2 <- p1 + geom_text_repel(data = subset(asasec, Year == 2014 & Revenues > 7000), size = 2) p3 <- p2 + labs( x = "Membership", y = "Revenues", color = "Section has own Journal", title = "ASA Sections", subtitle = "2014 Calendar year.
Show Several Fits at Once, with a Legend Model-based Graphics Tidy Model Objects with Broom get component-level statistics with tidy() Get observation-level statistics with augment() Grouped Analysis Plots for Surveys p <- ggplot(data = gapminder, mapping = aes(x = log(gdpPercap), y = lifeExp)) p + geom_point(alpha = 0.1) + geom_smooth(color = "tomato", fill = "tomato", method = MASS::rlm) + #robust regression line geom_smooth(color = "steelblue", fill = "steelblue", method = "lm") p + geom_point(alpha = 0.
Chapter 2 Chapter 3 Wrong way to set color Aesthetics Can Be Mapped per Geom Save plots Chapter 4 Group data and the “Group” Aesthetic Facet to make small multiples Geoms can transform data Histgrams and Density Plots Avoid Transformations When Necessary Chapter 2 geom_point
p <- ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) p + geom_point() Chapter 3 geom_smooth
Chapter 5 Use Pipes to Summerize Data Continuous Variables by Group or Category Write and Draw in the Plot Area Scales, Guides, and Themes Chapter 5 Use Pipes to Summerize Data rel_by_region <- gss_sm %>% group_by(bigregion, religion) %>% summarize(N = n()) %>% mutate(freq = N / sum(N), pct = round((freq*100), 0)) ## Warning: Factor `religion` contains implicit NA, consider using ## `forcats::fct_explicit_na` rel_by_region ## # A tibble: 24 x 5 ## # Groups: bigregion [4] ## bigregion religion N freq pct ## <fct> <fct> <int> <dbl> <dbl> ## 1 Northeast Protestant 158 0.
Panel data with one way fixed effect mm1 <- invforward ~ TOBINQ + inv + top3 + size + lev + cash + loss + lnage + cfo + sd + ic + factor(year) zzz <- plm(mm1,data=sample,model="within",index=c("stkcd")) same as xtreg i.year fe , without robust vcetype 用这种方法算出来$R^2$和Stata报告$R^
效應評估模型 “提高最低工資是否會減少就業?” “最低工資提高是否餐廳的全職員工數會減少?” 假設 $MinWage$為「最低工資有提高」的虛擬變數
效應評估模型 \[ mrall=mrall_{-BeerTax}+\beta^*BeerTax \] 提高啤酒稅(BeerTax)是否有助減低車禍死亡率(mrall)? 固定效應模型 令 $W$代表「州愛喝酒程度」。 $W$與 $mr
OLS estimator The method to compute (or estimate) $b_0$ and $b_1$ we illustrated above is called Ordinary Least Squares, or OLS. $b_0$ and $b_1$ are therefore also often called the OLS coefficients. By solving problem
\[ \begin{align} e_i & = y_i - \hat{y}_i = y_i - \underbrace{\left(b_0 + b_1 x_i\right)}_\text{prediction}\\ e_1^2 + \dots + e_N^2 &= \sum_{i=1}^N e_i^2 \equiv \text{SSR}(b_0,b_1) \\ (b_0,b_1) &= \arg \min_{\text{int},\text{slope}} \sum_{i=1}^N \left[y_i - \left(\text{int} + \text{slope } x_i\right)\right]^2 \end{align} \]
效應評估模型 \[Y_{i}={Y}_{-p,i}+\beta_i P_{i}\] \[ Y_i=Y_{-P,i}+\beta^* P_i \] \[ \begin{equation} Y_i=\beta_0+\beta_1P_i+w_i'\gamma+\varepsilon \tag{3.2} \end{equation} \] 在$w_{i}$條件下,「香煙售價」$P_{i}$必需要與「非價格效應的香煙銷售量」$Y_{-P}$獨立