Here is what I would like to do.
Code:
gen farminglivestock2=. replace farminglivestock2=2 if q12a>0 & q12a<10 replace farminglivestock2=2 if q12b>0 & q12b<10 label variable farminglivestock2 "Farming/ Tending Livestock" label define farminglivestock2 2 "Yes" label value farminglivestock2 farminglivestock2
But I need to account for both q12a and q12b in my command. I tried to use the replace code "replace farminglivestock2=2 if q12a>0 & q12a<10 & q12b>0 & q12b<10" and "replace farminglivestock2=2 if q12a>0 & q12a<10 | q12b>0 & q12b<10" but each time it did not show the full amount of people I need (it basically did not include questions which had a value over 1 and less than 10 for both q12a and q12b).
q12a q12b
0 1
1 0
1 2 --> when I try to run both codes, it drops the 3 times when q12a and q12b both have values over 1 and less than 10, as seen here
So Is there a way to, like the example, be able to individually run the replace statements so that no variables are dropped? Or, is there a way to ensure that when there is a situation where both q12a and q12b have a value which meets the criteria, it is not dropped? I hope this makes sense!
For reference, I am using Stata 15.0! And sorry in advance for not using dataex (this is my first time posting so I am still trying to work things out). I installed it but the example set it generated did not include the example I wanted to show! If there are also suggestions on how to change the range of the example set, I would appreciate advice on that as well!
0 Response to Is it possible to add multiple recode commands to one newly generated variable?
Post a Comment