0

I think I know what I need to do, I just don't know how to make it work.

Example of Data: data

I have decades of data in Excel in that format, which I uploaded to R. I believe I need to convert it to a time series or date format somehow, but retain the countries as categories so I can run the following regressions:

y ~ x1+x2 
x1 ~ x2
y ~ x1 

Can anyone share code/packages that can help me accomplish this? It feels simple, but I could not find any examples in a few hours of searching. Would ggplot also be recommended for producing figures with this data?

I tried converting it to as.xts, but that did not work, likely because of my poor understanding and the Country column. My failed attempt below:

modelts=as.xts(model1[,-1],order.by=as.Date(model1[,1],format='%m%d%Y'))
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
tryhard
  • 1
  • 2

1 Answers1

0

Your data is a great fit for a tsibble:

as_tsibble(your_df, key = "Country", index = "Year")

You can then use the wonderful tidyverts tools: Tidy tools for time series

These use ggplot2 and dplyr.

A great guide for these tools is: Forecasting: Principles and Practice (3rd ed)

Isaiah
  • 2,091
  • 3
  • 19
  • 28