I'm trying to generate a new set of variables from two parallel lists in Stata. I have a set of columns that are the percentage of each demographic group in the labor force and another set of columns that are the percentage of each demographic group in a particular occupation. I want to divide the latter by the former to create a crowding score for each group.
local pct_lf "pct_lf_tot_Male-pct_lf_tot_o_f_65_plus
* pct in labor force by demo group
local pct_occ "pct_Male-pct_o_f_65_plus"
* pct in occupation by demo group
local n : word count `pct_occ'
forvalues i = 1/`n' {
local a : word `i' of `pct_lf'
local b : word `i' of `pct_occ'
gen crd_`b'=`b'/`a'
}
There's a syntax error with this code which I haven't figured out. I am wondering is there another way to do this? Generate a new variable by dividing a list of variables by another list of variables in order as parallel lists?