0

I need to do a 2SLS fixed effects regression in R on my panel data set, but I am really lost at the moment. I ran the model with fixest, but it returned a negative R squared. I also tried to run it with plm but I am not sure if I wrote the correct code for that or if 2SLS is possible at all with plm. The results I got from plm greatly differed from the ones using fixest. So I basically have two questions:

Do fixest and plm use different methods to estimate the same models in general and is that why they generate different results for the same regressions?

And is 2SLS even possible at all in the plm package?
This is the only info I could find on that matter, it is taken from https://cran.r-project.org/web/packages/plm/plm.pdf. What is am not sure about exactly is the syntax of the instruments here:

## Instrumental variable estimations
# replicate Baltagi (2013/2021), p. 133/162, table 7.1
data("Crime", package = "plm")
FE2SLS <- plm(lcrmrte ~ lprbarr + lpolpc + lprbconv + lprbpris + lavgsen +
ldensity + lwcon + lwtuc + lwtrd + lwfir + lwser + lwmfg + lwfed +
lwsta + lwloc + lpctymle + lpctmin + region + smsa + factor(year)
| . - lprbarr - lpolpc + ltaxpc + lmix,
data = Crime, model = "within")

Does this code mean that lprbarr and lpolpc are instrumented by ltaxpc and lmix? And what if I only wanted lprbarr to be instrumented by ltaxpc and lmix. Would the correct syntax after the pipe operator be

| . - lprbarr + ltaxpc + lmix     
Helix123
  • 3,502
  • 2
  • 16
  • 36
Lars
  • 1
  • 2
  • Hello @Lars. Welcome to SO! Please, provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that other SO users can help you in the best way. Cheers – lovalery Nov 10 '21 at 18:41
  • Without seeing any of your code, we also don't know if your code is correct. If the question is more about the methods behind the code, it should be moved to [stats.se]; if it's about the code itself, it's fine here but needs an example to work with – camille Nov 10 '21 at 19:12
  • You should [edit] the post to include additional information. Also see the recommendations on making a [reproducible example](https://stackoverflow.com/q/5963269/5325862) – camille Nov 10 '21 at 20:02

1 Answers1

1

Most certainly, 2SLS (here FE2SLS - fixed effects 2SLS) is possible with the plm package.

In the packages 1st vignette [1], you can read about the multi-part formula

In some circumstances, standard formulas are not very useful to describe a model, notably while using instrumental variable like estimators: to deal with these situations, we use the Formula package.

The Formula package provides a class which enables to construct multi-part formula, each part being separated by a pipe sign (|).

The two formulas below are identical:

 emp ~ wage + capital | lag(wage, 1) + capital 
 emp ~ wage + capital | . -wage + lag(wage, 1)

In the second case, the . means the previous parts which describes the covariates and this part is “updated.” This is particularly interesting when there are a few external instruments.

[1] https://cran.r-project.org/web/packages/plm/vignettes/A_plmPackage.html

Helix123
  • 3,502
  • 2
  • 16
  • 36
  • Thanks! So if I, hypothetically, wanted wage to be instrumented by ```lag(wage, 1)``` and additionally, e.g., ```tax```, I would just add it after the pipe, right? Such that: ```emp ~ wage + capital | . -wage + lag(wage, 1) + tax```. And do you happen to know if it's possible to see the first-stage regression output in ```plm```? – Lars Nov 12 '21 at 09:30