Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Last active December 21, 2015 12:49
Show Gist options
  • Save cigrainger/6308390 to your computer and use it in GitHub Desktop.
Save cigrainger/6308390 to your computer and use it in GitHub Desktop.
Dissertation code, CEX data
require(RSQLite)
require(mitools)
require(stringr)
require(plyr)
#Import data and create panel data set
for(i in 2007:2011){
setwd("~/Documents/CEX0711")
year <- i
db.name <- paste( "ces.fmly" , year , "db" , sep = "." )
setwd( paste( getwd() , year , sep = "/" ) )
yr <- substr( year , 3 , 4 )
keptvariables <- c('newid','cuid','interi','qintrvmo','qintrvyr','bls_urbn','fam_size','fam_type','no_earnr','num_auto','perslt18','persot64','popsize','region','smsastat','vehq','state','vehql','psu','age_ref','educ_ref','ref_race','sex_ref','inclass','transpq','transcq','cartknpq','cartkncq','cartkupq','cartkucq','othvehpq','othvehcq','gasmopq','gasmocq','pubtrapq','pubtracq','num_tvan','totexppq','totexpcq','respstat')
if((as.numeric(yr)+1)<10){
load( paste0( "./intrvw/fmli" , yr , "1x.rda" ) )
load( paste0( "./intrvw/fmli" , yr , "2.rda" ) )
load( paste0( "./intrvw/fmli" , yr , "3.rda" ) )
load( paste0( "./intrvw/fmli" , yr , "4.rda" ) )
load( paste0( "./intrvw/fmli" , 0, as.numeric( yr ) + 1 , "1.rda" ) )
fmly <- get( paste0( "fmli" , yr , "1x" ) )
fmly$qtr <- 1
for ( i in 2:4 ){
x <- get( paste0( "fmli" , yr , i ) )
x$qtr <- i
fmly <- rbind.fill( fmly , x )
}
x <- get( paste0( "fmli", 0 , as.numeric( yr ) + 1 , "1" ) )
x$qtr <- 5
fmly <- rbind.fill( fmly , x )
rm( x )
rm(
list =
c(
paste0( "fmli" , yr , "1x" ) ,
paste0( "fmli" , yr , 2:4 ) ,
paste0( "fmli" , 0 , as.numeric( yr ) + 1 , "1" )
)
)
}
else{
load( paste0( "./intrvw/fmli" , yr , "1x.rda" ) )
load( paste0( "./intrvw/fmli" , yr , "2.rda" ) )
load( paste0( "./intrvw/fmli" , yr , "3.rda" ) )
load( paste0( "./intrvw/fmli" , yr , "4.rda" ) )
load( paste0( "./intrvw/fmli" , as.numeric( yr ) + 1 , "1.rda" ) )
fmly <- get( paste0( "fmli" , yr , "1x" ) )
fmly$qtr <- 1
for ( i in 2:4 ){
x <- get( paste0( "fmli" , yr , i ) )
x$qtr <- i
fmly <- rbind.fill( fmly , x )
}
y <- get( paste0( "fmli", as.numeric( yr ) + 1 , "1" ) )
x$qtr <- 5
fmly <- rbind.fill( fmly , x )
rm( x )
rm(
list =
c(
paste0( "fmli" , yr , "1x" ) ,
paste0( "fmli" , yr , 2:4 ) ,
paste0( "fmli" , as.numeric( yr ) + 1 , "1" )
)
)
}
gc()
fmly <- subset(fmly, select=keptvariables)
assign(paste("fmly", yr, sep=""),fmly)
rm(fmly)
}
#Bind the dataframes
data <- rbind(fmly07,fmly08,fmly09,fmly10,fmly11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment