Skip to content

Instantly share code, notes, and snippets.

@azadag
Last active August 29, 2015 14:01
Show Gist options
  • Save azadag/ffbd065d979ceb6d9802 to your computer and use it in GitHub Desktop.
Save azadag/ffbd065d979ceb6d9802 to your computer and use it in GitHub Desktop.
PERWT pums data...
## read in pums data (here to a dataframe called "b" ##
library(data.table)
dfMa<-data.frame(b$INDb,b$OCC1990b,b$pwmetro,b$perwt) ## toggle detailed
colnames(dfa) <- c("IND", "OCC", "PWMETRO","PERWT")
###build cross matrix using data.table #####
#### Convert data frame to Data Table
dtaa <- data.table(dfMa,key="IND,OCC,PWMETRO")
resa <- dtaa[,list(n=sum(PERWT)),by=list(IND,OCC,PWMETRO)] ## sum by weighted variable
res1a <-resa[,transform(.SD,pind=n/sum(n)),by=list(IND,PWMETRO)] ## create percent of employment in each industry by city
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment