[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: RE: Taking averages, etc.
At 10:55 AM 12/17/2003 +0000, Nick Cox wrote:
That is very interesting Nick and something I might well have screwed up
sooner or later. Form 1 looks very much like the SPSS if command; but it
works very differently. Form 2 is what SPSS users will want as their
equivalent to the SPSS if.
Non-programmers should note the crucial difference
in principle between
1. if <condition> <command>
2. <command> if <condition>
Form 1 carries out _one_ test of the <condition>
supplied. If it is true, <command> is carried
out, but not otherwise.
Form 2 carries a test of the <condition>
supplied for _every_ observation specified
and then carries out <command>
for the observations for which it is true.
I'm probably just missing it, but it seems that Stata does not have a
convenient if-then-else structure, i.e. the equivalent of SPSS's DO IF
command. In SPSS, I could do something like
DO IF X1 = 1 and X2 = 3
Compute Y = 3.
ELSE IF X3 = 2 and X4 = 17
Compute Y = 4.
Compute Y = 5.
In SPSS, this would result in Y equaling 3, 4, 5, or missing for all
cases. If, say, X1 = 1, X2 = 3, X3 = 2, X4 = 17, Y would be coded 3, i.e.
only the first compute would be executed.
In stata, it seems to me like I would have to write increasingly
complicated if statements to achieve the same thing; something like
gen y = 3 if X1==1 & X2==3
replace y = 4 if X1 !=1 & X2 !=3 & X3==2 & X4==17
replace y = 5 if X1 !=1 & X2 !=3 & X3 !=2 & X4 !=17
or something like that. Is that correct, or is there an easier way I am
Richard Williams, Associate Professor
OFFICE: (574)631-6668, (574)631-6463
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
* For searches and help try: