2

I have a pdata.frame for 14 years x 89 observations and 10 variables + 4 dummies.

Those dummies variables are only for filtering (when necessary) my data. When using Stata, I just add an "if VAR==1" at the end of my code. How to use this with plm package in R?

Examples
Stata code

quietly xtreg y x1 x2 if x3==1, fe

R code

plm( y ~ x1 + x2, data = PANEL, model = "within")

Must I create separate panels, already filtered data, or is it possible to do it while running plm?

Adilson V Casula
  • 164
  • 1
  • 16

1 Answers1

3

You can either use the subset option in plm (subset=) or you subset the data before fitting it

Using the dataset from the package, subset on region ==6,

library(plm)
data("Produc", package = "plm")
fit1 = plm(gsp ~ hwy + pc, data = Produc, subset = region == 6)
fit2 = plm(gsp ~ hwy + pc, data = subset(Produc, region == 6))
identical(coefficients(fit1), coefficients(fit2))
Helix123
  • 3,502
  • 2
  • 16
  • 36
StupidWolf
  • 45,075
  • 17
  • 40
  • 72