Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: New package -ifwins- "if wins!" on SSC to subset data by "if" exp first then "in" range


From   Dan Blanchette <[email protected]>
To   [email protected]
Subject   st: New package -ifwins- "if wins!" on SSC to subset data by "if" exp first then "in" range
Date   Wed, 18 Mar 2009 10:33:24 -0400 (EDT)

Dear Statalist Members,
Thanks to Kit Baum, a new package -ifwins-
is now available for download on SSC.

Description
-ifwins- is a prefix command that runs most any Stata command that does not modify
the dataset in memory (e.g. generate, replace, etc.).  -ifwins- will have "if" subset
the dataset before "in" subsets the dataset.  This is the opposite of what happens
when both "if" and "in" are used in the same Stata command.  For example, the following
code will first subset the dataset to the first 10 observations and then subset
the dataset to the specified condition:

 . sysuse auto
 . list if foreign == 1 in 1/10

Since the auto.dta dataset is sorted by the variable foreign, the above code will
not list any observations because in the first 10 observations foreign == 0 . So, "if" looses and "in" wins when "battling" over which one subsets the dataset
before the other one does.

If you want to run a Stata command on a certain number of observations when a
certain condition exists, you would have to:

 . preserve
 . keep if foreign == 1
 . list in 1/10 make turn weight
 . restore

or use -ifwins- as a prefix to the desired Stata command:

 . ifwins if foreign == 1 in 1/10 :  list make turn weight

The above will list the first 10 observations of when the variable foreign is
equal to 1 (one).  So now "if" wins!...but "in" is still helpful.

To install -ifwins-:
. ssc install ifwins

Let me know if you have any questions.

Thanks to Roy Wada for helping me better document -ifwins-.

Dan Blanchette
Research Associate
Center of Entrepreneurship and Innovation
Duke University's Fuqua School of Business
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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