[R] Help on np package - how to set the data into a panel format
Rui Barradas
ruipbarradas at sapo.pt
Sat Jul 13 15:55:36 CEST 2013
Hello,
It would be better if you post a data example. Like this, I will make up
one. I'm not sure I understand the question, but if you want to change
your data from long to wide format there are several ways of doing it.
# Make up some data
dat <- data.frame(
year = rep(1:2, each = 3),
country = rep(letters[1:3], 2),
value = rnorm(6))
# Now in wide format
reshape(dat, idvar = "year", timevar = "country", direction = "wide")
# Using package reshape2
#install.packages("reshape2", dependencies = TRUE) # do this only once
library(reshape2) # load it into the R session
dcast(dat, year ~ country)
Hope this helps,
Rui Barradas
Em 13-07-2013 12:30, serena masino escreveu:
> Hi,
>
> I am new to R and am a STATA user. I am using R as I need the np package to
> perform a local linear non parametric regression on a panel data of
> countries. My data contains 138 countries, each observed for 31 years, from
> 1981 to 2011.
>
> I am aware of the panel package in R which sets the data in panel format
> telling R which one is the "id" and which one is the "time" variable. I am
> not sure however what to use to set the data into a panel format when using
> the np package.
>
> What I have done so far was to
>
> read.csv ("C:/folder/filename.csv")
>
> then i explore it
> str(filename)
>
> and my country variable appears as a "factor", which I think is good right?
> Because it means that is a string to which R has attached a value.Year
> instead appears as "int".
>
> Now, how can I tell R that the data has repeated country cross sections for
> 31 years and so that the data should be treated as a panel of 138 countries
> observed each for 31 consecutive years?
>
> Many Thanks in advance for your help, and apologies if this is a very basic
> question, I have tried looking it up in a number of places but all I came
> by was the panel package instructions and I am not sure whether they can
> transfer to the np package too.
>
> Best,
> Serena
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list