azadag
5/28/2014 - 2:12 AM

PERWT pums data...

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