简体   繁体   中英

How to run State Level Fixed Effects with PLM

I am trying to run a regression with only state level fixed effects, but not time fixed effects.

I am trying:

lm1 <- plm(lnwage ~ age + age^2 + education, data = cps, index = "state", model = "within")

But I am not having any luck, and I am only finding information online of people using state and time fixed effects at the same time.

To calculate any fixed effects we can add a dummy for the variable concerned, ok? Let's consider the example right there in the plm() documentation and do first an ordinary lm() with the state dummy for states fixed effects.

data("Produc", package = "plm")

fe.lm <- lm(log(gsp) ~ 0 + log(pcap) + log(pc) + log(emp) + unemp + 
              factor(state), data=Produc)

> summary(fe.lm)$coef
                                Estimate   Std. Error    t value
log(pcap)                   -0.026149654 0.0290015755 -0.9016632
log(pc)                      0.292006925 0.0251196728 11.6246309
log(emp)                     0.768159473 0.0300917394 25.5272539
unemp                       -0.005297741 0.0009887257 -5.3581508
factor(state)ALABAMA         2.201617056 0.1760038727 12.5089126
factor(state)ARIZONA         2.368088138 0.1751884949 13.5173725
factor(state)ARKANSAS        2.263015801 0.1671716685 13.5370773
...

Now we use plm() where we also have to add the dummy, it isn't shown in the output, though.

library(plm)
fe.plm <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp + factor(state),
              data=Produc, index=c("state","year"), model="within")

> summary(fe.plm)$coef
              Estimate   Std. Error    t-value      Pr(>|t|)
log(pcap) -0.026149654 0.0290015755 -0.9016632  3.675200e-01
log(pc)    0.292006925 0.0251196728 11.6246309  7.075069e-29
log(emp)   0.768159473 0.0300917394 25.5272539 2.021455e-104
unemp     -0.005297741 0.0009887257 -5.3581508  1.113946e-07

Another option is felm() .

library(lfe)
fe.felm <- felm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp | state | 0, 
                data=Produc) 

> summary(fe.felm)$coef
              Estimate   Std. Error    t value      Pr(>|t|)
log(pcap) -0.026149654 0.0290015755 -0.9016632  3.675200e-01
log(pc)    0.292006925 0.0251196728 11.6246309  7.075069e-29
log(emp)   0.768159473 0.0300917394 25.5272539 2.021455e-104
unemp     -0.005297741 0.0009887257 -5.3581508  1.113946e-07

As one can see, everything yields the same values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM