prediction
prediction copied to clipboard
variable "fitted" not ordered after using prediction for plm model
Please specify whether your issue is about:
- [x] a possible bug
- [ ] a question about package functionality
- [ ] a suggested code or documentation change, improvement to the code, or feature request
If you are reporting (1) a bug or (2) a question about code, please supply:
- a fully reproducible example using a publicly available dataset (or provide your data)
- if an error is occurring, include the output of
traceback()
run immediately after the error occurs - the output of
sessionInfo()
Put your code here:
###Description of data and problem: data is artifical and enough for problem description,
### it describes something over different IDs and time (panel).
###After estimation (package plm, pooling, for simplicity using only a lag of endogen. variable)
### I used prediction package to forecast one ahead (t+n) in time. Results (variable "fitted") of this prediction is correct but not in the right order of the panel: a first forecasted value refers to the first ID but not to t+1, second value belongs to (ID2,t+1) and not ID1, t+1), third value belongs to ID3,t+1 (and not to ID1,t+3) and so on. To sum up: data for "fitted" is sorted by ID first and not for ID and time. Please correct. Thany you!
## load package
library("prediction")
library(plm)
## code goes here
library(prediction)
library(plm)
library(readxl)
library(panelr)
library(stargazer)
#load data, note the last 5 observations for each ID are n.a. to make predictions
panel1<-read_excel("C:/your_place/test1.xlsx")
#declare pabel structure
panel1<-pdata.frame(panel1, index=c("ID","time"))
panel1$time <- as.Date(as.character(panel1$time), format = "%Y")
#estimate model
pooled_p1 <- plm(Y~lag(Y), panel1, model="pooling")
#checking results for making pocket calculator predictions
stargazer(pooled_p1, type="text", title="Lag1", digits=2, column.labels = c("Pooled"))
#making predictions
#making a subsample to predict
panel1_sub<-subset(panel1,time>="0017-05-19") #you have to update month and day to actual date!
Forecast_pooled_p1<-prediction(pooled_p1, data = panel1_sub)
#check the data
## session info for your system
sessionInfo()