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.

**Exercise 1**

Install and load the `AER`

and `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.

**Exercise 2**

Now that the data is loaded in both `R`

and `Stata`

, print summary statistics equivalent to `Stata`

‘s `summarize`

, `describe`

and `list in 1/6`

.

**Exercise 3**

Fit the following linear model and print a summary of the estimated parameters:

ln(wage) = α + β_{1}education + β_{2}experience + β_{3}experience^{2} + β_{4} female

**Exercise 4**

Add a dummy for African American and `test`

whether the coefficients on the experience variables are jointly statistically significant from zero.

**Exercise 5**

Translate: `twoway scatter lwage experience`

.

**Exercise 6**

Make a histogram of log(wages): `hist lwage`

.

**Exercise 7**

`drop south`

from your data (frame) object.

**Exercise 8**

Find the equivalent of `mean(wage) if married == 1 & gender == 2`

, that is the mean wage for not married females.

**Exercise 9**

Make a two by two frequency table: `tabulate occupation union`

.

**Exercise 10**

Estimate a logistic regression with `married`

as an independent variable and `education`

and `experience`

as dependent variables. Estimate the marginal effect of an increase in education at the mean (`margins, dydx(education) atmeans`

).

**What's next:**

- Explore all our (>1000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below

## Leave a Reply