TableAPS1 <- subset(TableAP, year >= 1959) ?? John Kane Kingston ON Canada
> -----Original Message----- > From: iamsta...@gmail.com > Sent: Wed, 31 Oct 2012 20:19:46 -0700 (PDT) > To: r-help@r-project.org > Subject: [R] Subsetting year range > > Hi, > > I have a panel data set that I am trying to subset. I am trying to keep > values for years >=1960. > The full set is from 1940 to 2000. > > I tried a few things, but none worked. Here are a couple that I am trying > to > use. > > TableAPS1 <- subset(TableAP, year => 1959) > > TableAPS1 <- TableAP[ which(year > 1959),] > > > It would be really nice if someone can point out what I am doing wrong > with > this part, or somewhere else that I am coding wrong. > > Thanks, > > > Full code: > > ########### > TableAP <- read.csv("AnnualPanel.csv") > TableAP <- data.frame(TableAP) > TableAP > nrow (TableAP) > > install.packages("zoo") > require(zoo) > > Lagpolity4AP1 <- lag(zoo(TableAP$polity4), -1) > Lagpolity4AP2 <- lag(zoo(TableAP$polity4), -2) > Lagpolity4AP3 <- lag(zoo(TableAP$polity4), -3) > Lagpolity4AP4 <- lag(zoo(TableAP$polity4), -4) > Lagpolity4AP5 <- lag(zoo(TableAP$polity4), -5) > LaglrgdpchAP1 <- lag(zoo(TableAP$lrgdpch), -1) > LaglrgdpchAP2 <- lag(zoo(TableAP$lrgdpch), -2) > LaglrgdpchAP3 <- lag(zoo(TableAP$lrgdpch), -3) > LaglrgdpchAP4 <- lag(zoo(TableAP$lrgdpch), -4) > LaglrgdpchAP5 <- lag(zoo(TableAP$lrgdpch), -5) > > TableAP <- cbind(zoo(TableAP), Lagpolity4AP1, Lagpolity4AP2, > Lagpolity4AP3, > Lagpolity4AP4, Lagpolity4AP5, > LaglrgdpchAP1, LaglrgdpchAP2, LaglrgdpchAP3, LaglrgdpchAP4, > LaglrgdpchAP5) > TableAP <- data.frame(TableAP) > > TableAP <- subset(TableAP, select = c(code, country, year, polity4, > Lagpolity4AP1, Lagpolity4AP2, Lagpolity4AP3, > Lagpolity4AP4, Lagpolity4AP5, lrgdpch, LaglrgdpchAP1, LaglrgdpchAP2, > LaglrgdpchAP3, LaglrgdpchAP4, LaglrgdpchAP5)) > > fix(TableAP) > > # Using data from 1960 to 2000 only > > ################################################################ > ################################################################ > TableAPS1 <- TableAP[ which(year > 1959),] > ################################################################ > ################################################################ > > # Keeping only rows with Sample = 1 > TableAP <- subset(TableAP, sample == 1) > > TableAPS1 <- subset(TableAPS1, select = c(code, country, year, polity4, > Lagpolity4, lrgdpch, Laglrgdpch)) > > TableAPS1<- ts(TableAPS1) > > # Run FE OLS with lag real GDP and lag democracy > # -1 is to subtract the intercept > > library(dyn) > > FEOLS <- dyn$lm(polity4 ~ -1 + Lagpolity4 + Laglrgdpch + factor(year)+ > factor(code), TableAPS1) > FEOLS > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Subsetting-year-range-tp4648096.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. ____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! ______________________________________________ R-help@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.