R studio 3 very simple question

0 comments

Data from here: https://canvas.uoregon.edu/courses/175081/files/fo…

Question 1:

Now, please download the dataset hw1_2018.csv onto your computer.

Make sure in R Studio you install two packages: tidyverse, and broom. I’ll walk you through your R script. Unless there is a double space, things go on the same line.

In your script file at the top type:

library(tidyverse)

library(broom)

To read in your dataset, next type (after updating the directory for where you put the data)

gross_test <- read_csv “C:/Users/benja/Dropbox/HealthvUndergrad/R examples/HW1.csv”)

Now run a linear regression of days_poor_health on age, and educ.

ols1 <- lm (days_poor_health ~ coll+age, data=gross_test)

tidy(ols1)

What is the estimated effect of education on days in poor health?

Question 2:

What is the estimated effect of age on days in poor health?

Question 3:

Next you need to estimate the first stage for an IV regression.

Type

###College Height as instrument
first <- lm (coll ~ act+age, data=gross_test)
tidy(first)

#### storing predicted values
coll_hat <- fitted(first)

What is the estimated effect of ACT test score on college completion?

Question 4:

Now you need to estimate the second stage of two stage least squares.

Type

### SEcond Stage

second <- lm (days_poor_health ~ coll_hat+age, data=gross_test)

###Final Output
tidy(second)

What is the estimated effect of college attainment on health now?

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}