Can any STATA users please help me with the query below.
I'm finding it a bit worrying that I'm using the if
commands below and in method 1 and method 2 STATA is not
returning what I think it should do.
In Method 1, it's making 2 changes when there is only 1
observation where sex==1, and then it's not making any
changes for the next command.
In Method 2, again, it's making 2 changes when there is
only 1 observation where sex==1.
Method 3 seems to be the only one that is correct.
Does somebody know why this is?
Thanks in advance.
Colleen
sex age pop
1. 1 1 0
2. 2 2 0
METHOD 1
. if sex==1 & age==1 {replace pop=1}
(2 real changes made)
. if sex==2 & age==2 {replace pop=2}
. list
sex age pop
1. 1 1 1
2. 2 2 1
METHOD 2
. if sex==1 {replace pop=3 if age==1
(1 real change made)
. replace pop=4 if age==2}
(1 real change made)
. list
sex age pop
1. 1 1 3
2. 2 2 4
METHOD 3
. replace pop=5 if sex==1 & age==1
(1 real change made)
. replace pop=6 if sex==2 & age==2
(1 real change made)
. list
sex age pop
1. 1 1 5
2. 2 2 6
----------------------
Colleen Elizabeth McGahan
[log in to unmask]
Tel: 0181 643 8901 Ext.4197
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|