Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: cancel a selection and continue working with all thevariables or category of a variable


From   Michael McCulloch <mm@pinest.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: cancel a selection and continue working with all thevariables or category of a variable
Date   Wed, 3 Sep 2008 06:22:46 -0700

Maarten,
In your strategy 2,
gen byte touse96 = yearfile == "1996"
reg y x if touse96 /// regression on selection
reg y x /// regression on complete file
what if you wanted to add a second level of selection, for example only children during 1996?
Can the command
gen byte touse96 = yearfile == "1996"
be written like this:?
gen byte touse96 = yearfile == "1996" & child==1
Michael




--- carmen gamarra <carmengamarra@hotmail.com> wrote:
 I know how I would like to cancel a selection and continue working
 with all the variables or category of a variable?

 Example:                     keep if  yearfile=="1996"

 and then (cancel select)   cancel the selection and working with all
 the categories:
-keep if expression- means you throw away everything for which
expression is false. Once you throw it away, it is gone forever (unless
you follow strategy 1 below).

There are two strategies you can follow:
1)
preserve
keep if yearfile == "1996"
reg y x /// regression on selection
restore
reg y x /// regression on complete file

2)
gen byte touse96 = yearfile == "1996"
reg y x if touse96 /// regression on selection
reg y x /// regression on complete file

see -help preserve- for more on strategy 1, and -help if- for more on
strategy 2. In most cases I would prefer strategy 2.

Hope this helps,
Maarten


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


*
* 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/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index