Hello,

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
Indiv_id is just an id for each individual subject/participant in the survey data. The country_code indicates which country the subject is from. And the indiv_disc variable is a dummy that indicates whether an individual is discriminated (1) or not (0).

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
I tried to create a dummy variable using the bysort and egen commands but I am not sure exactly how to do this. Any suggestions about what the code should be would be greatly appreciated.

Thank you,
Daniel