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

From |
Andrea Bennett <mac.stata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: is this a missing value issue? (-if- command used) |

Date |
Mon, 21 Jul 2008 15:56:08 +0200 |

Sorry, I already got the answer from my previous post (I just thought my personal logic would work, too!). Anyhow, one should use the following code:

qui lookfor zt

qui foreach var of varlist `r(varlist)' {

sum `var', mean

if r(mean)<=.1 {

drop `var'

}

}

On Jul 21, 2008, at 3:22 PM, Johannes Geyer wrote:

Hey Andrea,

I guess this is a FAQ:

http://www.stata.com/support/faqs/lang/ifqualifier.html

"if" works like "while" in your example, i.e. in case you have - `var'==.-

and "missing" is

a very large number the if-statement does not evaluate to "true" and does

not execute -drop `var'-. It

starts evaluating your data with the first observation. If the statement

is "false", Stata proceeds executing code after the if-statement.

Hope this helps,

Johannes

wner-statalist@hsphsun2.harvard.edu schrieb am 21/07/2008 15:05:02:

Hi!

I have the following code in my do-file:

qui lookfor zt

qui foreach var of varlist `r(varlist)' {

if `var'<=.1 {

drop `var'

}

}

All my zt* variables are percentages of missing values of the original

variables, e.g. zt_age_2000==0.04 means that 0.04 percent of the

variable age in year 2000 are missing. The way I generated the zt-

variables, they contain Stata missing values for all years except the

corresponding year, e.g. in the above case the zt_age_2000 variable

contains missing values for all years smaller and greater than 2000

while for the year 2000 it shows the percentage missing.

Now with the above query I want to get rid of zt-variable if their

missing percentage is below the threshold of 0.1. Strangely, when I

use the above commands, it does not perform what I want. However, when

I first recode each zt-variable and set the missing values to zero,

then the if-query works fine.

So, what am I doing wrong when using the if-command?

Many thanks for your considerations,

Andrea

*

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

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

**References**:**Re: st: is this a missing value issue? (-if- command used)***From:*Johannes Geyer <JGeyer@diw.de>

- Prev by Date:
**Re: st: mfx** - Next by Date:
**Re: st: drop variable on condition** - Previous by thread:
**Re: st: is this a missing value issue? (-if- command used)** - Next by thread:
**Re: st: is this a missing value issue? (-if- command used)** - Index(es):

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