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

st: AW: multiple IF commands


From   "Christian Holz" <[email protected]>
To   <[email protected]>
Subject   st: AW: multiple IF commands
Date   Wed, 6 Jul 2005 15:57:49 +0100

Bill,
You must put brackets:

keep if pov_rate >=(nat_pov+.01) | ue_rate>=(nat_ue+.01) | (ue_chg>=.4 &
ue_rate>nat_ue)

One more important thing to know is, that Stata stores missing values as
(very) big numbers. Therefore, for example, ue_chg>=.4 is also true when
ue_chg is a missing value.
Therefore you might want to include a !missing statement in your condition,
i.e.

keep if ( pov_rate >=(nat_pov+.01) | ue_rate>=(nat_ue+.01) | (ue_chg>=.4 &
ue_rate>nat_ue) ) & ( !mi(pov_rate) & !mi(ue_rate) & !mi(ue_chg) )

Greetings from Scotland,
Christian.

-----Urspr´┐Żngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von William P.
Kittredge
Gesendet: 06 July 2005 15:39
An: [email protected]
Betreff: st: multiple IF commands

Folks,

I'm just getting started with STATA and am trying to
get the IF command to select using multiple
catagories.

The 'do' file below is supposed to keep cases in which
one (or more) of the eligibility conditions applies:

poverty rate (pov_rate) >= national average plus 1
point (nat_avg) 
    OR
unemployment rate (ue_rate) >= national average
(ue_rate)

   OR

1 year change in unemployment rate (ue_chg) as long as
the resulting unemployment rate is > the national
average.

When I run this against known datasets, it fails to
drop the appropriate observations.  

Am I overlooking something obvious?

Here's the code:

use "C:\Documents and Settings\wkittredge\My
Documents\SACI STATA\book4.dta", clear
gen nat_pov = .106
gen nat_ue = .052
gen pov_rate = ncollpov/ncolpovu 
gen ue_rate =  bls_unempl_rate_04
gen ue_chg =  bls_unempl_rate_04 - bls_unempl_rate_03 
order pov_rate ue_rate ue_chg nat_pov nat_ue cdbgname
rgn state
keep if pov_rate >=(nat_pov+.01)|ue_rate>=
(nat_ue+.01)|ue_chg>=.4 & ue_rate>nat_ue
list pov_rate ue_rate ue_chg cdbgname state, clean


Thanks,

Bill Kittredge

William P. Kittredge, Ph.D.
Research Director
Center for the Study of Capital Markets and Democracy
voice: 571-344-5034
email: [email protected]
http://capitalmarketscenter.org/
"if to do were as easy as to know what were good to do,
chapels had been churches and poor men's cottages princes' palaces"
*
*   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