I want to createa variable which indicates if a woman has some idea about family planning. For that i have combined 4 variables . The variable thus created =1 if any of the 4 variables is 1 and its 0 otherwise.
There are no missing values in any of the 4 variables.
So i tried creating it in two ways -
First way is creating a variable with all missing values and then replacing them with 0 and 1 depending on the conditions .
second way is creating a variable with all values 0 and replacing the values which is 1 in any of the 4 variables with 1.
the result from both methods should be the same but its not. why?
have included the results below.
gen fam_pl = .
(259627 missing values generated)
.
. replace fam_pl = 1 if v384a == 1 | v384b ==1| v384c ==1| s616d ==1
(169700 real changes made)
. replace fam_pl = 0 if v384a == 0 | v384b ==0| v384c ==0| s616d ==0
(238870 real changes made)
. tabulate fam_pl
fam_pl | Freq. Percent Cum.
------------+-----------------------------------
0 | 238,870 92.01 92.01
1 | 20,757 7.99 100.00
------------+-----------------------------------
Total | 259,627 100.00
. gen famp = 0
.
. replace famp = 1 if v384a == 1 | v384b ==1| v384c ==1| s616d ==1
(169700 real changes made)
. tabulate famp
famp | Freq. Percent Cum.
------------+-----------------------------------
0 | 89,927 34.64 34.64
1 | 169,700 65.36 100.00
------------+-----------------------------------
Total | 259,627 100.00
There are no missing values in any of the 4 variables.
So i tried creating it in two ways -
First way is creating a variable with all missing values and then replacing them with 0 and 1 depending on the conditions .
second way is creating a variable with all values 0 and replacing the values which is 1 in any of the 4 variables with 1.
the result from both methods should be the same but its not. why?
have included the results below.
gen fam_pl = .
(259627 missing values generated)
.
. replace fam_pl = 1 if v384a == 1 | v384b ==1| v384c ==1| s616d ==1
(169700 real changes made)
. replace fam_pl = 0 if v384a == 0 | v384b ==0| v384c ==0| s616d ==0
(238870 real changes made)
. tabulate fam_pl
fam_pl | Freq. Percent Cum.
------------+-----------------------------------
0 | 238,870 92.01 92.01
1 | 20,757 7.99 100.00
------------+-----------------------------------
Total | 259,627 100.00
. gen famp = 0
.
. replace famp = 1 if v384a == 1 | v384b ==1| v384c ==1| s616d ==1
(169700 real changes made)
. tabulate famp
famp | Freq. Percent Cum.
------------+-----------------------------------
0 | 89,927 34.64 34.64
1 | 169,700 65.36 100.00
------------+-----------------------------------
Total | 259,627 100.00
Comment