I have individual-level data that looks like this:
| indiv_id | country_code | indiv_disc_dummy | 
| 1 | 1 | 0 | 
| 2 | 1 | 0 | 
| 3 | 1 | 0 | 
| 4 | 2 | 1 | 
| 5 | 2 | 0 | 
| 6 | 2 | 1 | 
| 7 | 3 | 1 | 
| 8 | 3 | 1 | 
| 9 | 3 | 1 | 
I would like to create a dummy variable that indicates whether an individual lives in a country where there is discrimination (to be coded as 1) or where there is not discrimination (to be coded as 0). I want the code to take all the indiv_id for a particular country code and generate a new variable that gives 1 if any of those indiv_id in a particular year
have been discriminated (indiv_disc=1) or code it as 0 if none of the individuals in a particular country have been discriminated (indiv_disc=0). So For my example data above, there would be a new var called country_disc_dummy in a fourth column with the following values:
| indiv_id | country_code | indiv_disc_dummy | country_disc_dummy | 
| 1 | 1 | 0 | 0 | 
| 2 | 1 | 0 | 0 | 
| 3 | 1 | 0 | 0 | 
| 4 | 2 | 1 | 1 | 
| 5 | 2 | 0 | 1 | 
| 6 | 2 | 1 | 1 | 
| 7 | 3 | 1 | 1 | 
| 8 | 3 | 1 | 1 | 
| 9 | 3 | 1 | 1 | 
Thank you,
Daniel
0 Response to Generating new dummy var in an individual level dataset that gives country-year level information for each individual
Post a Comment