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

st: RE: multiple IF commands


From   "Steichen, Thomas J." <[email protected]>
To   <[email protected]>
Subject   st: RE: multiple IF commands
Date   Wed, 6 Jul 2005 10:50:18 -0400

You have:

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

You need:

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

Note the parentheses binding "ue_rate > nat_ue" only to "ue_chg >= ..4".


Your original statement has 4 independent clauses and says keep records only if 1 of the first 3 clauses is true AND the last clause
is true.

You need, instead, just 3 clauses, where the last is a compound clause.

Tom

Thomas J. Steichen
[email protected]
----------------------------------------------------------------------------
  Facts do not cease to exist because they are ignored. - Aldous Huxley
----------------------------------------------------------------------------



> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> William P. Kittredge
> Sent: Wednesday, July 06, 2005 10:39 AM
> To: [email protected]
> Subject: 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/
> 

-----------------------------------------
CONFIDENTIALITY NOTE:  This e-mail message, including any  attachment(s),
contains information that may be confidential,  protected by the attorney-
client or other legal privileges, and/or  proprietary non-public
information.  If you are not an intended  recipient of this message or an
authorized assistant to an intended  recipient, please notify the sender by
replying to this message and  then delete it from your system.  Use,
dissemination, distribution,  or reproduction of this message and/or any of
its attachments (if  any) by unintended recipients is not authorized and
may be unlawful.


*
*   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