Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: newbie if {} else {} question


From   Daniel Muller <[email protected]>
To   <[email protected]>
Subject   st: RE: newbie if {} else {} question
Date   Thu, 19 Sep 2002 21:59:45 +0200

I'm also not an expert and don't know how to accomplish that with an
if-loop.

However, another possibility is:

. egen ascertgp=group(probip promig)

Daniel

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Richard
> Herrell
> Sent: Thursday, September 19, 2002 9:27 PM
> To: statalist
> Subject: st: newbie if {} else {} question
>
>
> I've just started learning Stata syntax after long years of SAS use and am
> completely stumped by a result.  I want to create a new 4-level variable
> (ascertgp) based on the crosstabulation of 2 dichotomous variables (probip
> and promig).  This is the syntax I wrote:
>
> if      probip==1 & promig==1 {
>   gen ascertgp=1
> }
> else if probip==0 & promig==1 {
>   gen ascertgp=2
> }
> else if probip==1 & promig==0 {
>   gen ascertgp=3
> }
> else if probip==0 & promig==0 {
>   gen ascertgp=4
> }
>
> When I run tab1 ascertgp I get a value of 3 for every observation.  (I
> know what the 4 frequencies should be from the crosstab.)  I must be doing
> something very obviously wrong, but can see what it is.
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index