I'm new to the forum, but here it goes. I have the following code, where I'm just trying to get responses back when more than 50% of respondents chose option 2 (which was "Bad").
quietly foreach var in Q25_1 Q25_2 Q25_3 Q25_4 Q25_5 Q25_6 Q25_7 Q25_8 Q25_9 Q25_10 Q25_11 Q25_12 Q25_13{
count if (`var'==2)
local num=r(N)noisily tab `var'
count if (`var'==1|`var'==2|`var'==3)
local den=r(N)
local frac=`num'/`den'
if `frac'>=0.05 {
noisily display "Question `var': `frac'"
}
}
However, I also want to run this for different genders (I have 5 options of gender: 1==Cisgender man, 2== Trans man, 3== Cisgender woman, 4== Trans Woman, 5== Nonbinary). I want the same code to run for each of them, so I can compare the results and see if any group has more negative responses than others to the same question.
This is what I've tried but haven't gotten good results.
foreach i in 1 2 3 4 5{
quietly foreach var in Q25_1 Q25_2 Q25_3 Q25_4 Q25_5 Q25_6 Q25_7 Q25_8 Q25_9 Q25_10 Q25_11 Q25_12 Q25_13 if Gender==`i'{
count if (`var'==2)noisily tab `var'
local num=r(N)
count if (`var'==1|`var'==2|`var'==3)
local den=r(N)
local frac=`num'/`den'
if `frac'>=0.05 {
noisily display "Question `var': `frac'"
}
}
Any help will be appreciated!
Best
Miguel
0 Response to Conditioning for values within a variable while using foreach
Post a Comment