Originally posted by Nick Cox
View Post
Code:
|
* Example generated by -dataex-. To install: ssc install dataex |
clear |
input double(Q2061A Q609) int _freq |
1 1 3327 |
1 2 4949 |
1 3 1144 |
1 98 124 |
1 99 41 |
1 . 172 |
2 1 1310 |
2 2 2131 |
2 3 444 |
2 98 47 |
2 99 22 |
2 . 574 |
3 1 172 |
3 2 275 |
3 3 78 |
3 98 7 |
3 99 2 |
3 . 10 |
6 1 417 |
6 2 649 |
6 3 154 |
6 98 12 |
6 99 1 |
6 . 92 |
7 1 721 |
7 2 1128 |
7 3 206 |
7 98 18 |
7 99 8 |
7 . 70 |
8 1 280 |
8 2 357 |
8 3 99 |
8 98 11 |
8 99 5 |
8 . 13 |
11 1 666 |
11 2 705 |
11 3 254 |
11 98 18 |
11 99 4 |
11 . 9 |
12 1 911 |
12 2 1197 |
12 3 255 |
12 98 24 |
12 99 5 |
12 . 270 |
13 1 446 |
13 2 567 |
13 3 123 |
13 98 16 |
13 99 1 |
13 . 12 |
14 1 317 |
14 2 458 |
14 3 162 |
14 98 13 |
14 99 6 |
14 . 10 |
15 1 261 |
15 2 385 |
15 3 118 |
15 98 40 |
15 99 8 |
15 . 58 |
98 1 103 |
98 2 96 |
98 3 39 |
98 98 14 |
98 99 0 |
98 . 61 |
99 1 22 |
99 2 9 |
99 3 5 |
99 98 0 |
99 99 0 |
99 . 41 |
. 1 0 |
. 2 1 |
. 3 0 |
. 98 0 |
. 99 0 |
. . 0 |
end |
label values Q2061A Q2061A |
label def Q2061A 1 "economic situation", modify |
label def Q2061A 2 "financial and administrative corruption", modify |
label def Q2061A 3 "democracy and representation/governance", modify |
label def Q2061A 6 "internal stability and security", modify |
label def Q2061A 7 "foreign interference", modify |
label def Q2061A 8 "religious extremism", modify |
label def Q2061A 11 "fighting terrorism", modify |
label def Q2061A 12 "public services", modify |
label def Q2061A 13 "security", modify |
label def Q2061A 14 "political/party issues", modify |
label def Q2061A 15 "other", modify |
label def Q2061A 98 "don't know", modify |
label def Q2061A 99 "refused", modify |
label values Q609 Q609 |
label def Q609 1 "religious", modify |
label def Q609 2 "somewhat religious", modify |
label def Q609 3 "not religious", modify |
label def Q609 98 "don't know", modify |
label def Q609 99 "refused", modify |
And here's the code:
. bysort Q2061A Q609: gen freq = _N if Q609 == 1
(70 missing values generated)
. by Q2061A (Q609) : replace freq = -freq[_N]
(14 real changes made, 14 to missing)
. egen group = group(freq Q2061A)
(84 missing values generated)
. labmask group, values(Q2061A) decode
no observations
When I used this command: by Q2061A (Q609) : replace freq = -freq[_N] with a binomial variable like gender, things worked smoothly, but now I end up replacing the variables with missings.
Comment