Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: looping through variables that are not consecutive and have common stem in name
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: looping through variables that are not consecutive and have common stem in name
Date
Wed, 15 Jan 2014 21:25:48 +0000
Something this should be sufficient:
gen count_sub300 = 0
qui foreach v of var correct* {
replace count_sub300 = count_sub300 + (`v' < 300)
}
Notes:
1. You said that you were only interested in the -time*- variables,
but your code looks at the -correct*- variables.
2. `v' < 300 & `v' < . reduces to `v' < 300.
Nick
[email protected]
On 15 January 2014 21:12, David de Jong <[email protected]> wrote:
> I have the variables time1 correct1 time2 correct2 etc.
>
> I'd like to loop through only the time variables, counting values that
> are under 300 and not missing. I'm trying to use something like this:
>
> qui forval j = 1/164 {
>
> qui foreach v correct`j' {
>
> replace count_sub300 = count_sub300 + (`v' < 300 & `v' < .)
>
> }
>
> }
>
> It's not working. I'm quite sure that the 2nd line is not correct, but
> can't figure out what it should be. Can anyone advise?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/