serena masino
2013-Jul-13 11:30 UTC
[R] Help on np package - how to set the data into a panel format
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]]
Rui Barradas
2013-Jul-13 13:55 UTC
[R] Help on np package - how to set the data into a panel format
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. >
John Kane
2013-Jul-13 15:30 UTC
[R] Help on np package - how to set the data into a panel format
We really need to see the data, I think. You can use the function dput(), see ?dput dput(filename) will give you a formatted output that you can just copy and paste into an e-mail. An R-help reader can just copy and paste that into R and have an exact copy of your data set. John Kane Kingston ON Canada> -----Original Message----- > From: serenamasino at gmail.com > Sent: Sat, 13 Jul 2013 12:30:34 +0100 > To: r-help at r-project.org > Subject: [R] Help on np package - how to set the data into a panel format > > 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.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails