The speed and simplicity of
Stata for the most basic modeling applications is amazing. However, for many of us who have switched to
R, the flexibility, the community, and the fact that
R is open source makes it, at least, a powerful complement.
These exercises focus on some of the most commonly used commands in Stata and how we can reproduce them in R.
Solutions are available here. Note that the flexibility and the vast number of packages for
R means there are often many perfectly valid ways to reach our ends.
Install and load the
foreign packages. Load the
PSID1982 data to your
R environment. Furthermore, save a copy of it in
.dta format to your hard drive so you can open it in Stata also and compare commands.
Now that the data is loaded in both
Stata, print summary statistics equivalent to
list in 1/6.
Fit the following linear model and print a summary of the estimated parameters:
ln(wage) = α + β1education + β2experience + β3experience2 + β4 female
Add a dummy for African American and
test whether the coefficients on the experience variables are jointly statistically significant from zero.
twoway scatter lwage experience.
Make a histogram of log(wages):
drop south from your data (frame) object.
Find the equivalent of
mean(wage) if married == 1 & gender == 2, that is the mean wage for not married females.
Make a two by two frequency table:
tabulate occupation union.
Estimate a logistic regression with
married as an independent variable and
experience as dependent variables. Estimate the marginal effect of an increase in education at the mean (
margins, dydx(education) atmeans).