Skip to content

Instantly share code, notes, and snippets.

@Robinlovelace
Created August 20, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robinlovelace/b9c0207ca465885120ccfeaa70380545 to your computer and use it in GitHub Desktop.
Save Robinlovelace/b9c0207ca465885120ccfeaa70380545 to your computer and use it in GitHub Desktop.
age4 <- c(346,81,435)
age5_19 <- c(580,420,1730)
age20_34 <- c(726,354,1321)
age35_64 <- c(1296,823,2567)
age65 <- c(2028,1112,2883)
male <- c(2448,1349,4273)
female <- c(2528,1441,4663)
White <- c(3464,2646,3912)
Black <- c(1443,7,3449)
Hispanic <- c(14,93,310)
Other_race <- c(55,44,1265)
employed <- c(1998,1476,4543)
unemployed <- c(116,51,319)
not_laborf <- c(2862,1263,4074)
cons_gaga <- data.frame(age4,age5_19,age20_34,age35_64,age65,male,female,
White,Black,Hispanic,Other_race,employed,unemployed,not_laborf)
age4 <- c(0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1)
age5_19 <- c(1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,0,0,0,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1,0,1,1,1,0,0,1,0,1,1,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,1,1)
gaga_ind_cat <- data.frame(age4,age5_19,age20_34,age35_64,age65,male,female,White,Black,Hispanic,Other_race,employed,unemployed,not_laborf)
weights_gaga <- array(NA, dim=c(100,3))
gaga_ind_agg <- matrix(colSums(gaga_ind_cat), 3, 14, byrow = T)
library(ipfp) # load the ipfp package -may need install.packages("ipfp")
cons_gaga <- apply(cons_gaga, 2, as.numeric) # convert the constraints to 'numeric'
gaga_ind_catt <- t(gaga_ind_cat) # transpose the dummy variables for ipfp
x0 <- rep(1, 100) # set the initial weights
weights_gaga_f <- apply(cons_gaga, 1, function(x) ipfp(x, gaga_ind_catt, x0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment