0
votes

I am new to R and I need to conduct a time-series, cross-sectional (TSCS) analysis in R (dynamic probit). I know how to run the model, but I need to tell R that I am dealing with TSCS data.

I have data for 44 countries (countries are both coded numerically and in character form in the data set), and for 52 years for each of these. E.g:

Angola 1950
Angola 1951
.
.
.
Benin 1950
Benin 1951

I have found the ts() command, but I am not sure if I have used it correctly. My code so far is:

outdata50time <- ts(data=outdata50, start=1950, end=2002)

Will that do the trick? Or do I need different classes for the countries?

Thanks for your help!

1
I am confusing with your question. What do you expect to have? when you type head(outdata50time) what do you have? - agstudy
if I type "head(outdata50time)" then I get [1] NA NA NA NA NA NA. I am used to tell the programme from years in STATA that I am using time series data. That is all I want to do. I just got confused with what exactly I have to provide in the the ts() command to properly set it as TSCS data. - Florian Reiche
The output I get from dput(outdata50) is huge and is not even fully displayed. I have 44 cross-sections, and 52 years of analysis. All I want to tell R now before running my dynamic probit model, is that I have time-series, cross-sectional data, that "year" is my time variable and that the "country number" is my cross section variable. Or do I not have to do that in R? - Florian Reiche

1 Answers

1
votes

Load the data set (I added some data points to the data set in the question):

library(data.table)
test <- data.table(structure(list(Country = structure(c(1L, 1L, 2L, 2L), .Label = c("Angola", 
"Benin"), class = "factor"), Year = c(1950L, 1951L, 1950L, 1951L
), Data = c(23L, 24L, 45L, 64L)), .Names = c("Country", "Year", 
"Data"), class = "data.frame", row.names = c(NA, -4L)))

Once you got this, I would create some sort of a loop to extract the data related to each country. An example for one country would be the following:

ts <- ts(test[Country=="Benin"]$Data, start=(1950), frequency=1)
ts
Time Series:
Start = 1950 
End = 1951 
Frequency = 1 
[1] 45 64