Mace
Mace

Reputation: 1269

Instrumental variable estimation by systemfit and 2SLS in R

I am trying to do this simple instrumental variables estimation in R using the package systemfit and two stage least squares (2SLS):

y = b + b1*x1 + b2*x2 + b3*w + e

where x1 and x1 are the endogenous variables I would like to instrument, w is an exogenous variable, and e is the residual. My two instruments are z1 and z2. I want to use z1 for x1 and z2 for x2. Thus, my 1st stage regressions would be

x1 = c + c1*z1 + c2*z2 + c3*w + e1
x2 = d + d1*z1 + d2*z2 +d3*w + e2

I have tried:

systemfit(y~x1 + x2 + w,inst=~z1 + z2 +w)

But is unsure that this is correct...

Upvotes: 1

Views: 5420

Answers (3)

Niccolo Stamboglis
Niccolo Stamboglis

Reputation: 1

I would definitely use ivreg to estimate 2SLS models. Sometimes uploading the AER package might be tricky if you do not have updated versions of R (check which package better fits you R version if you get stuck!).

Upvotes: 0

coffeinjunky
coffeinjunky

Reputation: 11514

Why don't you use the ivreg from the AER package? You could try it and compare the results.

 #install.packages("AER") # if not already installed
 library(AER)
 ?ivreg

Upvotes: 3

BiXiC
BiXiC

Reputation: 973

I think systemfit function can handle only one endogenous variable per equation. Try to do this in 2 steps.

lm1 <- lm(x1 ~ z1 + w, data = yourDataFrame) 
lm2 <- lm(x2 ~ z2 + w, data = yourDataFrame)
yourDataFrame$x1.1st.step <- lm1$fitted
yourDataFrame$x2.1st.step <- lm2$fitted

lm.2nd.step <- lm(y ~ x1.1st.step + x2.1st.step + w, data = yourDataFrame)

Upvotes: 1

Related Questions