panel-data

Model Prediction for pooled regression model in panel data

旧巷老猫 提交于 2019-12-11 09:07:59
问题 I'm trying to produce a predictive model where i performed multiple pooled regressions in each year (based on previous years) and thus allow coefficients to vary across time. (This might not make sense in the sample data provided, but it is done in practice for my sample). Here is what I came up so far: I adjusted my code to a reproducible sample from the plm package: The data is structured in the following way (panel) with firm, year indexed. > head(Grunfeld) firm year inv value capital 1 1

Python, plotting Pandas' pivot_table from long data

别等时光非礼了梦想. 提交于 2019-12-11 05:59:00
问题 I have a xls file with data organized in long format. I have four columns: the variable name, the country name, the year and the value. After importing the data in Python with pandas.read_excel, I want to plot the time series of one variable for different countries. To do so, I create a pivot table that transforms the data in wide format. When I try to plot with matplotlib, I get an error ValueError: could not convert string to float: 'ZAF' (where 'ZAF' is the label of one country) What's the

Sorting xts data to look like panel data in R

安稳与你 提交于 2019-12-11 02:55:48
问题 I need to use 'PerformanceAnalytics' package of R and to use this package, it requires me to convert the data into xts data. The data can be downloaded from this link: https://drive.google.com/file/d/0B8usDJAPeV85elBmWXFwaXB4WUE/edit?usp=sharing . Hence, I have created an xts data by using the following commands: data<-read.csv('monthly.csv') dataxts <- xts(data[,-1],order.by=as.Date(data$datadate,format="%d/%m/%Y")) But after doing this, it looses the panel data structure. I tried to sort

Correlation matrix in panel data in R

十年热恋 提交于 2019-12-10 23:28:07
问题 I have a time-series panel dataset which is structured in the following way: df <- data.frame( year = c(2012L, 2013L, 2014L, 2012L, 2013L, 2014L), id = c(1L, 1L, 1L, 2L, 2L, 2L), c = c(11L, 13L, 13L, 16L, 15L, 15L) ) #> year id c #> 1 2012 1 11 #> 2 2013 1 13 #> 3 2014 1 13 #> 4 2012 2 16 #> 5 2013 2 15 #> 6 2014 2 15 I would like to find the cross-correlation between values in column C given their id number. Something similar to this: #> 1 2 #> 1 1 0.8 #> 2 0.8 1 I have been using dplyr

Drop variable in panel data in R conditional based on a defined number of consecutive observations

我只是一个虾纸丫 提交于 2019-12-10 22:23:13
问题 I am quite new to R, my problem is as follows: I have a set of panel data organised as time series like this(only part is shown): Week_Starting Team A Team B Team C Team D 2010-01-02 1 2 3 4 2010-01-09 2 40 1 5 2010-01-16 15 <NA> 4 11 2010-01-23 25 <NA> 7 18 2010-01-30 38 <NA> 9 29 2010-02-06 <NA> <NA> 12 34 2010-02-13 <NA> <NA> 16 40 2010-02-20 <NA> <NA> 20 <NA> 2010-02-27 <NA> <NA> 15 28 2010-03-06 <NA> <NA> 20 <NA> 2010-03-13 <NA> <NA> 24 <NA> 2010-03-20 <NA> <NA> 24 <NA> 2010-03-27 <NA>

Long/wide data to wide/long

删除回忆录丶 提交于 2019-12-10 13:33:27
问题 I have a data frame that look as follow: import pandas as pd d = {'decil': ['1. decil','1. decil','2. decil','2. decil','3. decil','3. decil'], 'kommune': ['AA','BB','AA','BB','AA','BB'],'2010':[44,25,242,423,845,962], '2011':[64,26,239,620,862,862]} df = pd.DataFrame(data=d) Printing decil kommune 2010 2011 1. decil AA 44 64 1. decil BB 25 26 2. decil AA 242 239 2. decil BB 423 620 3. decil AA 845 862 3. decil BB 962 862 My desired output is something like this kommune year 1. decil 2. decil

Analysing a data frame that contains a time series using stargazer

↘锁芯ラ 提交于 2019-12-10 10:42:20
问题 I have a panel data set of 10 obs. and 3 variables. (# of obs. 30 = 10 rows (= countries) * 2 columns (= migration parameters) * 1col for the respective year. My data frame consists of 3 annual data frames, so to say. How can I apply stargazer on the whole period of time by taking into account that it is a panel data set (so max N=10)? That is, R should start over after every 11th row. I'd like to get the pretty table for descriptive statistics The data set for the first three years:

R - Using data.table to efficiently test rolling conditions across multiple rows and columns

你。 提交于 2019-12-10 10:35:20
问题 I am trying to test a variety of conditions in a data.table that looks like this reproducible example set.seed(17) year <- 1980 + rnbinom(10000,3,0.35) event <- rep(LETTERS, length.out=10000) z <- as.integer(runif(10000,min = 0, max = 10)) dt <- data.table(event,year,z) setkey(dt, event,year) dt <- dt[,sum(z), by=c("event","year")] V1 (which emerges from the last command) represents a count of event occurences. So the data table is an ordered array and I need to execute a variety of functions

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

R:repeating aggregate values for daily values in a panel setting [duplicate]

橙三吉。 提交于 2019-12-08 14:00:25
问题 This question already has answers here : How to join (merge) data frames (inner, outer, left, right) (13 answers) Closed 3 years ago . I have a data frame that has aggregate data over every 5 days(called a week in the dataset). > dput(Sample3) structure(list(Firm = c("ENG", "ENG", "ENG", "ENG", "ENG", "AUS", "AUS", "AUS", "AUS", "AUS", "NZ", "NZ", "NZ", "NZ", "NZ"), Week = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5), TotalSales = c(200, 155, 195, 150, 155, 140, 145, 150, 155, 160, 120, 125