I'm having trouble generating a variable using the absolute value of another variable. I want to indicate if population has changed (increased or decreased) by 5%. I'm able to generate an indicator for 5% increase but not decrease using the code below.
First, I calculated 5% (per5) of the total end of year population (totend). Second, I generated an indicator variable if per5 is greater or equal to the difference in totals (diffb). I'm sure it is obvious that this only creates a variable indicating a 5% increase but I also want to indicate decrease. I've experimented with the absolute values function, but I had no luck.
gen per5= .05*totend
gen change5=1 if (diffb>=per5)
Any suggestions? Thanks in advance for help.
First, I calculated 5% (per5) of the total end of year population (totend). Second, I generated an indicator variable if per5 is greater or equal to the difference in totals (diffb). I'm sure it is obvious that this only creates a variable indicating a 5% increase but I also want to indicate decrease. I've experimented with the absolute values function, but I had no luck.
gen per5= .05*totend
gen change5=1 if (diffb>=per5)
Any suggestions? Thanks in advance for help.
Comment