Home > Mobile >  Calculating the number of id's from a felm estimation
Calculating the number of id's from a felm estimation

Time:05-11

I'm estimating a series of country and year fixed-effects panel models using the felm function. I would like to calculate the number of countries included in each estimation. I can easily do this if I run my regressions using the plm function, as shown below. However, I don't want to run my regressions using plm for other reasons. Is there a way of calculating the number of id's used in a felm estimation?
a sample code is given below:

library(plm); library(lfe)
data("Grunfeld", package = "plm")
reg_plm <- plm(inv ~ value   capital,   data = Grunfeld, model = "within", effect = "twoways")
reg_felm <- felm(inv ~ value   capital  | 
                  firm   year, data=Grunfeld)

pdim(reg_plm)[["panel.names"]]$id.names 

Note that my data is an unbalanced panel and pdim does not work with a felm object.

CodePudding user response:

Using str(reg_felm) - as it is usual in such cases, in search of objects - reveals that the fixed effects are stored in fe.

We could display the levels

levels(reg_felm$fe$firm)
# [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

where their number is

length(levels(reg_felm$fe$firm))
# [1] 10

or use a table to see if it's balanced.

reg_felm$fe$firm |> table()
#  1  2  3  4  5  6  7  8  9 10 
# 20 20 20 20 20 20 20 20 20 20 
  • Related