Hi,
The two-stage least squares procedure we have in Zelig is based on
the systemfit package which takes a system of more than one equation
along with instrumental variables as inputs. What you have in mind is
slightly different from that procedure is identical to tsls() in sem
package. Unfortunately, we don't have that included in Zelig yet.
Maybe, you would like to contribute?
Kosuke
---------------------------------------------------------
Kosuke Imai Office: Corwin Hall 041
Assistant Professor Phone: 609-258-6601
Department of Politics Fax: 973-556-1929
Princeton University Email: kimai(a)Princeton.Edu
Princeton, NJ 08544-1012
---------------------------------------------------------
On Aug 7, 2007, at 3:24 PM, Andy Harris wrote:
Hi,
I've run across a problem in the two stage least squares model in
Zelig, which may be due to my code or to a bug. I want to use 2SLS
for an instrumental variable regression. However, whenever I
attempt to do so, I get an error:
Error in checkNrReq(modelNumEqn, userNumEqn, modelPar) :
The parameter "mu" requires between 2
and Inf equation(s). You have provided 1 See model doc.
for more details
I've provided some simulated data and the code that produces the
error below. Note that I used the same syntax as published in the
Zelig manual. Any thoughts on where I/zelig might be going wrong?
Doing the procedure with lm() seems to recover the correct parameters.
Many thanks,
Andy
nn<-1000 #sample size
V<-rnorm(nn) #confounding omitted variable
W<-rnorm(nn) #instrument
X<-rnorm(nn) #exogenous regressor
Z<-rep(NA, nn) #instrumental var. holder
for (i in 1:nn){
+ Z[i]<-rnorm(1, mean=V[i]+W[i]) #instrumental var as a
function of
instrument and omitted variable.
+ }
Y<-rep(NA, nn)
for (i in 1:nn){
+ Y[i]<-rnorm(1, mean=V[i]+0.25*Z[i]) #outcome as func of
omitted
var. and Z.
+ }
data<-as.data.frame(cbind(X,W,Z,Y))
names(data)<-c("X","W", "Z", "Y")
### using the 2sls syntax in section 12.48 of the zelig manual
fml <- list ("mu" = Y ~ X + Z,
+ "inst" = Z ~ W + X)
z.out <- zelig(formula = fml, model =
"twosls", data=data)
Error in checkNrReq(modelNumEqn, userNumEqn,
modelPar) :
The parameter "mu" requires between 2
and Inf equation(s). You have provided 1 See model doc.
for more details
### 2sls using lm()
lm.out1<-lm(Z~W+X, data=data)
lm.out2<-lm(Y ~ X + lm.out1$fitted, data=data)
summary(lm.out1)
Call:
lm(formula = Z ~ W + X, data = data)
Residuals:
Min 1Q Median 3Q Max
-3.7840 -0.9809 0.0200 0.9883 4.2447
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.00241 0.04329 -0.06 0.96
W 0.99100 0.04236 23.39 <2e-16 ***
X 0.02788 0.04414 0.63 0.53
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.37 on 997 degrees of freedom
Multiple R-Squared: 0.355, Adjusted R-squared: 0.353
F-statistic: 274 on 2 and 997 DF, p-value: <2e-16
summary(lm.out2)
Call:
lm(formula = Y ~ X + lm.out1$fitted, data = data)
Residuals:
Min 1Q Median 3Q Max
-4.975 -1.122 -0.055 1.105 5.361
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.00901 0.05170 -0.17 0.86164
X -0.04195 0.05274 -0.80 0.42653
lm.out1$fitted 0.18591 0.05104 3.64 0.00028 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.63 on 997 degrees of freedom
Multiple R-Squared: 0.0135, Adjusted R-squared: 0.0116
F-statistic: 6.85 on 2 and 997 DF, p-value: 0.00111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andy Harris
Ph.D. Candidate
Department of Government
Harvard University
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: