plm

R plm time fixed effect model

可紊 提交于 2019-12-11 06:46:52
问题 I found these sample codes online on fixed effect model: Code 1 fixed.time <- plm(y ~ x1 + factor(year), data=Panel, index=c("country", "year"), model="within") Code 2 fixed.time <- plm(y ~ x1, data=Panel, index=c("country", "year"), model="within") What is the difference? Doesn't index with country,year mean the fixed effect model actually create a dummy variable for year? The documentation does not explain this very clearly. 回答1: In plm , specifying the index arguments just formats the data

R: plm individual and time fixed effects but no other regressors

不羁岁月 提交于 2019-12-10 18:53:39
问题 I want to run a regression including only time and individual fixed effects (i.e. no other right-hand side variables). I try to do this with plm : plm(y ~ -1,data=data, effect="twoways", model="within") However, the syntax is not correct, nor does it work to just suppress the -1 from the model formula. The error message is: Error in uniqval[as.character(effect), , drop = F] : incorrect number of dimensions What is the correct syntax with plm for a regression of y on only time and individual

Lagging Forward in plm

↘锁芯ラ 提交于 2019-12-10 12:48:06
问题 This is a very simple question, but I haven't been able to find a definitive answer, so I thought I would ask it. I use the plm package for dealing with panel data. I am attempting to use the lag function to lag a variable FORWARD in time (the default is to retrieve the value from the previous period, and I want the value from the NEXT). I found a number of old articles/questions (circa 2009) suggesting that this is possible by using k=-1 as an argument. However, when I attempt this, I get an

R: Plotting panel model predictions using plm & pglm

风格不统一 提交于 2019-12-10 09:27:00
问题 I've created two regression models using a linear panel model with plm, and a generalized panel model using poisson with the pglm package. library(plm); library(pglm) data(Unions) # from pglm-package punions <- pdata.frame(Unions, c("id", "year")) fit1 <- plm(wage ~ exper + rural + married, data=punions, model="random") fit2 <- pglm(wage ~ exper + rural + married, data=punions, model="random", family="poisson") I now want to compare the two fits graphically by plotting the fitted values in a

first-difference linear panel model variance in R and Stata

雨燕双飞 提交于 2019-12-09 05:47:49
问题 I would like for a colleague to replicate a first-difference linear panel data model that I am estimating with Stata with the plm package in R (or some other package). In Stata, xtreg does not have a first difference option, so instead I run: reg D.(y x), nocons cluster(ID) In R, I am doing: plm(formula = y ~ -1 + x, data = data, model = "fd", index = c("ID","Period")) The coefficients match, but the standard errors in R are larger than in Stata. I looked in the plm help and pdf documentation

Problems with within and random models in plm package

牧云@^-^@ 提交于 2019-12-08 07:41:02
问题 I am working with plm package and I have problem with random and within models, which are giving errors which says "empty model". However, the model is not empty. In the source code for plm.fit, where the error originates it says something like (writing from the top of my head...) X <- model.matrix(formula,data, lhs=1,...) if (ncol(X) == 0) stop("empty model") however if I try to replicate this behaviour with the commands I am inputing into the original function, it gives ncol(X) is 17 or

fixed effects in R: plm vs lm + factor()

[亡魂溺海] 提交于 2019-12-06 10:29:40
问题 I'm trying to run a fixed effects regression model in R. I want to control for heterogeneity in variables C and D (neither are a time variable). I tried the following two approaches: 1) Use the plm package: Gives me the following error message formula = Y ~ A + B + C + D reg = plm(formula, data= data, index=c('C','D'), method = 'within') duplicate couples (time-id)Error in pdim.default(index[[1]], index[[2]]) : I also tried creating first a panel using data_p = pdata.frame(data,index=c('C','D

plm: using fixef() to manually calculate fitted values for a fixed effects twoways model

你说的曾经没有我的故事 提交于 2019-12-05 15:57:33
问题 Please note: I am trying to get the code to work with both time & individual fixed effects, and an unbalanced dataset. The sample code below works with a balanced dataset. See edit below too, please I am trying to manually calculate the fitted values of a fixed effects model (with both individual and time effects) using the plm package. This is more of an exercise to confirm I understand the mechanics of the model and the package, I know I can get the fitted values themselves from the plm

Error computing Robust Standard errors in Panel regression model (plm,R)

和自甴很熟 提交于 2019-12-05 06:14:43
问题 I am using the plm library to run fixed effect regressions and the sandwich,lmtest libraries to compute robust standard errors. I have no problem running the regressions, but in some instances when I go to compute the standard errors I get the following error: library(plm) library(sandwich) library(lmtest) fe_reg <- plm(y ~ x + I(x^2)+factor(date), data=reg_data, index=c("id","date"), model="within") coeftest(fe_reg, vcov.=vcovHC(fe_reg, type="HC1")) RRuntimeError: Error in solve.default

Hausman type test in R

别来无恙 提交于 2019-12-05 02:08:46
问题 I have been using " plm " package of R to do the analysis of panel data. One of the important test in this package for choosing between "fixed effect" or "random effect" model is called Hausman type . A similar test is also available for the Stata. The point here is that Stata requires fixed effect to be estimated first followed by random effect. However, I didn't see any such restriction in the "plm" package. So, I was wondering whether " plm " package has the default "fixed effect" first