I have panel data with country-year unit of analysis for 100 countries and 100 years. I have three variables (discrimination_religion one, two, and three) that are categorical with values ranging from 0 to 4 with some missing (.) values. There are several steps to my code:
1. First, I want to recode the discrimination_religion variables so that any 4 value becomes 1, any value (0, 1, 2, or 3) becomes 0 and missing values stay as missing.
2. Second, with the recoded discrimination variable (1 for highest level of discrimination and 0 for not high level of discrimination), I want to multiply this recoded variable with demographic population percentage weights indicating what proportion of the population the religion represents.
3. Third, I want to add up each of the three religion discrimination scores (with demographic weights added) to get a total score of religious discrimination but discounted with each religion's population percentage.
country | year | discrimination_religion1 (0-4) | discrimination_religion2 | discrimination_religion 3 | recode_disc_rel1 | recode_disc_rel2 | recode_disc_rel3 | percent_religion1 | percent_religion 2 | percent_religion 3 | total_discrimination |
Afghanistan | 1971 | 4 | 3 | 2 | 1 | 0 | 0 | 50 | 30 | 20 | 50 |
Afghanistan | 1972 | 4 | 4 | 4 | 1 | 1 | 1 | 52 | 28 | 20 | 100 |
Albania | 1971 | 4 | 4 | . | 1 | 1 | . | 70 | 20 | 10 | 90 |
Albania | 1972 | 4 | 4 | 3 | 1 | 1 | 0 | 70 | 20 | 10 | 90 |
step 1: egen recode_disc_rel1=anymatch(discrimination_religion1 ) values(4)
step2 and 3: egen total_discrimination= recode_disc_rel1*percent_religion1 + recode_disc_rel2*percent_religion2 + recode_disc_rel3*percent_religion3
Does this code look about right? Is there any steps that I am forgetting? Does anymatch work in the way I think it will? Does the idea of multiplying the recoded religious discrimination variable iwth the percentage religion using the asterick work the way I intend.
Thank you very much in advance for any assistance.
Sincerely,
Daniel
0 Response to generating new variable that incorporates population weights
Post a Comment