plm

Generating a lagged time series cross sectional variable in R

谁说我不能喝 提交于 2019-12-05 01:24:27
问题 I am a new R user. I have a time series cross sectional dataset and, although I have found ways to lag time series data in R, I have not found a way to create lagged time-series cross sectional variables so that I can use them in my analysis. 回答1: Here's how you could use the lag() function with zoo (and panel series data): > library(plm) > library(zoo) > data("Produc") > dnow <- pdata.frame(Produc) > x.Date <- as.Date(paste(rownames(t(as.matrix(dnow$pcap))), "-01-01", sep="")) > x <- zoo(t

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

浪尽此生 提交于 2019-12-04 16:04:00
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')) But I have repeated observations in both columns. 2) Use factor() and lm: works well formula = Y ~

R plm lag - what is the equivalent to L1.x in Stata?

允我心安 提交于 2019-12-04 14:09:26
问题 Using the plm package in R to fit a fixed-effects model, what is the correct syntax to add a lagged variable to the model? Similar to the 'L1.variable' command in Stata. Here is my attempt adding a lagged variable (this is a test model and it might not make sense): library(foreign) nlswork <- read.dta("http://www.stata-press.com/data/r11/nlswork.dta") pnlswork <- plm.data(nlswork, c('idcode', 'year')) ffe <- plm(ln_wage ~ ttl_exp+lag(wks_work,1) , model = 'within' , data = nlswork) summary

enovia plm export to sap

亡梦爱人 提交于 2019-12-04 13:34:24
UPC creation UPC 结构 PLM 使用的UPC 是 14个数字组成的,兼容。 前两位为 0,后12位为有效数字,在SAP中0会被忽略,符合国际UPC通用 规则, 前一位为0,后13 位为有效数字,符合EAN规则 UPC 产生规则 具体规则一:7位 + 5位 + 1 位 13位 算法分解:假设前面固定7位 为 0715799 中间5位0开始计算,每次产生一个新的UPC,需要加一 最后一位的产生规则如下。 * 071579917350 6 -> 0+1+7+9+7+5=29 7+5+9+1+3+0=25*3=75 29+75=104 10-4=6 * 071579917351 3 -> 0+1+7+9+7+5=29 7+5+9+1+3+1=26*3=78 29+78=107 10-7=3 * 071579917352 0 -> 0+1+7+9+7+5=29 7+5+9+1+3+2=27*3=81 29+81=110 10-0=10 * 071579917353 7 -> 0+1+7+9+7+5=29 7+5+9+1+3+3=28*3=84 29+84=113 10-3=7 * 071579917355 1 -> 0+1+7+9+7+5=29 7+5+9+1+3+5=30*3=90 29+90=119 10-9=1 * 071579917356 8 -> 0+1+7+9+7

R: plm — year fixed effects — year and quarter data

守給你的承諾、 提交于 2019-12-04 04:08:28
I am having a problem setting up a panel data model. Here is some sample data: library(plm) id <- c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2) year <- c(1999,1999,1999,1999,2000,2000,2000,2000,1999,1999,1999,1999,2000,2000,2000,2000) qtr <- c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4) y <- rnorm(16, mean=0, sd=1) x <- rnorm(16, mean=0, sd=1) data <- data.frame(id=id,year=year,qtr=qtr,y_q=paste(year,qtr,sep="_"),y=y,x=x) I run the following regression using 'id' as the individual index and 'year' as the time index: reg1 <- plm(y ~ x, data=data,index=c("id", "year"), model="within",effect="time") Unfortunately, I

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

此生再无相见时 提交于 2019-12-04 01:27:59
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 object, from the two related questions ( here and here ). From the plm vignette (p.2), the underlying

面板数据学习笔记

≡放荡痞女 提交于 2019-12-04 00:01:55
面板数据的定义 在学习面板数据之前,我先介绍时间序列数据和截面数据的概念 时间序列数据:时间序列数据是指对同一对象在不同时间连续观察所取得的数据。它着眼于研究对象在时间顺序上的变化,寻找空间(对象)历时发展的规律。利用时间序列作样本时,要注意几个问题:一是所选择的样本区间内经济行为的一致性问题;二是样本数据在不同样本点之间不可比,需要对原始数据进行调整,消除其不可比因素;三是样本观测值过于集中,因而时间序列数据不适宜于对模型中反映长期变化关系的结构参数的估计;四是模型随机误差的序列相关问题。 **notes:两个关键词:同一个对象,不同时间,例如:2016-2018年上海市月度cpi同比数据。。 截面数据: 横截面数据是指在某一时点收集的不同对象的数据。它对应同一时点上不同空间(对象)所组成的一维数据集合,研究的是某一时点上的某种经济现象,突出空间(对象)的差异。横截面数据的突出特点就是离散性高。横截面数据体现的是个体的个性,突出个体的差异,通常横截面数据表现的是无规律的而非真正的随机变化。即计量经济学中所谓的“无法观测的异质性”。在分析横截面数据时,应主要注意两个问题:一是异方差问题,由于数据是在某一时期对个体或地域的样本的采集,不同个体或地域本身就存在差异;二是数据的一致性,主要包括变量的样本容量是否一致、样本的取样时期是否一致、数据的统计标准是否一致。 **notes

Hausman type test in R

本小妞迷上赌 提交于 2019-12-03 21:35:08
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 and then "random effect" second. For your reference, I mention below the steps in Stata and R that I

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

烂漫一生 提交于 2019-12-03 20:58:33
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(crossprod(demX)) system is computationally singular: reciprocal condition number = 1.84726e-25 I do not

Generating a lagged time series cross sectional variable in R

泪湿孤枕 提交于 2019-12-03 16:50:44
I am a new R user. I have a time series cross sectional dataset and, although I have found ways to lag time series data in R, I have not found a way to create lagged time-series cross sectional variables so that I can use them in my analysis. Here's how you could use the lag() function with zoo (and panel series data): > library(plm) > library(zoo) > data("Produc") > dnow <- pdata.frame(Produc) > x.Date <- as.Date(paste(rownames(t(as.matrix(dnow$pcap))), "-01-01", sep="")) > x <- zoo(t(as.matrix(dnow$pcap)), x.Date) > x[1:3,1:3] ALABAMA ARIZONA ARKANSAS 1970-01-01 15032.67 10148.42 7613.26