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

Re: st: How to drop some Observation in Stata, if they are out of range?

From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: How to drop some Observation in Stata, if they are out of range?
Date   Tue, 23 Sep 2008 09:46:16 +0100 (BST)

--- bumbuminc <[email protected]> wrote:
> I want to drop some Observations in Stata, who are out of a certain
> range.
> For example: I have 2 variables, the first one is an identnumber and
> the second one are the earnings.
> Now I want Stata to drop all the Observation who are under a minimum
> earning and all who are over a maximum earning and save this under a
> new variable.

You can either drop the observations (rows) that fall outside your
range, or you can create a variable (column) which identifies which
observations meet your criterium, but it doesn't make sense to do both
as in that case the variable identifying which observations are to be
used will be all ones. The latter option is safer as it keeps your data
intact, but it can be inconvenient in large samples and because you
will have to remember to add -if variablename==1- to all commands
afterwards. How to do this is best seen by showing an example. See the
example below:

*----------- begin example -----------
// create a variable
sysuse auto, clear
gen touse = mpg >= 20 & mpg <= 30
reg rep78 mpg if touse

// drop cases
sysuse auto, clear
drop if mpg < 20 | mpg > 30
reg rep78 mpg
*------------ end example ------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

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

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

*   For searches and help try:

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