I would like to define a label in a foreach because I have a lot of different possible values for the variable, as the table below shows.
For example, I would like to label 102 as "2 hours", 103 as "3 hours" and so on. The same for the number of days, months and years. I tried the command below but I didn't get the lables for any of the foreach commands. What is wrong and how can I do this without having to type all the possible values?
The results I got:
For example, I would like to label 102 as "2 hours", 103 as "3 hours" and so on. The same for the number of days, months and years. I tried the command below but I didn't get the lables for any of the foreach commands. What is wrong and how can I do this without having to type all the possible values?
Code:
/*jan96+: IDADE.CNV
267 Ignorado 000-999
1 < 1 hora 001-100
2 1-23 horas 101-123
25 < 1 dia, horas ign 200
26 1-29 dias 201-229
55 < 1 mes, dias ign 300
56 1-11 meses 301-311
67 menor de 1 ano ign 400
68 1-99 anos 401-499
167 100 anos 500
168 101-199 anos 501-599 */
label define idd 0 "Ignorado" 1/100 "< 1 hora" 101 "1 hora" 200 "< 1 dia" 201 "1 dia" 300 "< 1 mes" 301 "1 mes" 400 "< 1 ano" 401 "1 ano" 500 "100 anos" 501 "101 anos"
foreach t in 2/9 {
label define idd 10`t' "`t' horas" 20`t' "`t' dias" 30`t' "`t' meses" 40`t' "`t' anos" 50`t' "1`t' anos", add
}
foreach i in 10/23 {
label define idd 1`i' "`i' horas", add
}
foreach i in 10/29 {
label define idd 2`i' "`i' dias", add
}
foreach i in 10/11 {
label define idd 3`i' "`i' meses", add
}
foreach i in 10/99 {
label define idd 4`i' "`i' anos" 5`i' "1`i' anos", add
}
label values idade idd
The results I got:
Code:
idade | Freq. Percent Cum.
------------+-----------------------------------
Ignorado | 1 0.00 0.00
/ | 33 0.07 0.07
2 | 9 0.02 0.09
3 | 4 0.01 0.10
5 | 14 0.03 0.13
6 | 1 0.00 0.13
7 | 1 0.00 0.13
10 | 28 0.06 0.19
14 | 1 0.00 0.19
15 | 18 0.04 0.23
18 | 1 0.00 0.23
20 | 24 0.05 0.28
22 | 1 0.00 0.28
10/23 horas | 2 0.00 0.28
25 | 4 0.01 0.29
28 | 1 0.00 0.29
30 | 26 0.05 0.35
35 | 2 0.00 0.35
37 | 1 0.00 0.35
40 | 10 0.02 0.37
42 | 1 0.00 0.38
45 | 6 0.01 0.39
50 | 7 0.01 0.40
51 | 1 0.00 0.40
55 | 2 0.00 0.41
56 | 1 0.00 0.41
57 | 2 0.00 0.42
< 1 hora | 6 0.01 0.43
1 hora | 223 0.46 0.89
/ | 134 0.28 1.16
103 | 72 0.15 1.31
104 | 66 0.14 1.45
105 | 43 0.09 1.53
106 | 52 0.11 1.64
107 | 31 0.06 1.70
108 | 27 0.06 1.76

Comment