Coerce fixef to data frame in R (PLM package) -
i'd fixed effects fixed effects panel data regression data frame. this:
data("produc", package = "plm") zz <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = produc, index = c("state","year")) view(as.data.frame(fixef(zz)))
unfortunately, last statement not work.
my expected output data frame state
in first column , fixed effect in second.
i've googled, , come this: extract fixed effect , random effect in dataframe
unfortunately, answer not seem function.
this easy construct. first check kind of object fixef
returns:
str(fixef(zz)) #class 'fixef' atomic [1:48] 2.2 2.37 2.26 2.5 2.4 ... # ..- attr(*, "se")= named num [1:48] 0.176 0.175 0.167 0.201 0.173 ... # .. ..- attr(*, "names")= chr [1:48] "alabama" "arizona" "arkansas" "california" ... # ..- attr(*, "type")= chr "level"
this tells fixef
returns object of class 'fixef', @ core atomic vector of length 48. in addition class attribute there 3 attributes "se", "names" (which accessable names
function) , "type".
then can this:
data.frame(state = names(fixef(zz)), fixef = as.vector(fixef(zz))) # state fixef #1 alabama 2.201617 #2 arizona 2.368088 #3 arkansas 2.263016 # ...
as.vector
necessary because data.frame
tries coerce s3 object data.frame , there no corresponding method as.data.frame
.
Comments
Post a Comment