# Time Series Cross Sectional Analysis and Forecasting With R

cty time tl

Argentina 2009_Q4 3

Argentina 2010_Q1 2

Argentina 2010_Q2 7

Argentina 2010_Q3 7

Argentina 2010_Q4 10

Argentina 2011_Q1 7

Argentina 2011_Q2 7

Argentina 2011_Q3 1

Argentina 2011_Q4 7

Argentina 2012_Q1 5

The data set has around 40 countries with each country having quarterly data for 5 years. As I am new to R, can someone assist me with how to perform a cross sectional time series ARIMA/ARMA models etc. and forecast in R? Some basic codes to prepare the data, to perform analysis and forecast for this series as an example would be helpful.

• I would say that 20 observations is not so much for time series analysis. How about using some form of panel regression? – Analyst Aug 26 '14 at 9:21
• I think you understood it wrong. I have in total (40 countries * 5years * 4 quartes) observations. But still can you please elaborate on the Panel Regression? I only have column "tl" as the only data row. I mean what will I regress on? – Anjali Aug 28 '14 at 6:34

I would summarise it here for you. If your dataset is called df and you want to forecast for each of the 40 countries separately, then you can do so by using either of the packages- dplyr or data.table along with forecast:
library(dplyr) library(forecast) model_fits <- group_by(df, cty) %>% do(fit=auto.arima(.\$tl))
library(data.table) library(forecast) temp <- setDT(temp)[, list(AR = list(auto.arima(tl))), by = cty]