I need to make a variable showing whether an individual has not lived in a certain geografical area in all of 2020. I have 4 variables showing the geografical area code in March, June, September and December, kom20203, kom20206, kom20209, and kom202012, respectively. For this example, lets say the area codes of interest are 123, 456 and 789. So I want to make a variable taking the value '1' if the individual has not lived in area 123, 456 OR 789 in neither March, June, September or December 2020.
This is not what I want, but to show my reasoning: If I wanted to make "the reverse" variable showing if the individual had lived in the area codes all months of the year, I could do it by writing:
I am thinking that the 'inlist'-function takes the value 0 if the variable specified does not take any of the listed values so I am trying to create my variable writing:
...however this asigns the value 1 to all my observations and most of them have lived in the areacodes specified at least 1 month in 2020, so the command above does not create the desired variable.
Any help in creating my desired variable would be much appreciated, and for the intrinsic value of learning stata I am also interested in how learning how to use the inlist-function when I am interested in observations which does not take any of the values specified.
This is not what I want, but to show my reasoning: If I wanted to make "the reverse" variable showing if the individual had lived in the area codes all months of the year, I could do it by writing:
Code:
gen true= 0 replace true = 1 if /// inlist(kom20203, 123, 456, 789) & /// inlist(kom20206, 123, 456, 789) & /// inlist(kom20209, 123, 456, 789) & /// inlist(kom202012, 123, 456, 789) & ///
Code:
gen not = 0 replace not = 1 if /// inlist(kom20203, 123, 456, 789)==0 & /// inlist(kom20206, 123, 456, 789)==0 & /// inlist(kom20209, 123, 456, 789)==0 & /// inlist(kom202012, 123, 456, 789)==0 & ///
Any help in creating my desired variable would be much appreciated, and for the intrinsic value of learning stata I am also interested in how learning how to use the inlist-function when I am interested in observations which does not take any of the values specified.
Comment