Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | David de Jong <davidcdejong@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: looping through variables that are not consecutive and have common stem in name |
Date | Wed, 15 Jan 2014 16:58:38 -0500 |
Hi Nick, Thanks for all of that, and for pointing out the variable mix-up. Time for my afternoon coffee, apparently. Much appreciated! Best, David ~ David C. de Jong, MA Department of Clinical and Social Sciences in Psychology University of Rochester 214 Meliora Hall Rochester, NY 14627 On Wed, Jan 15, 2014 at 4:25 PM, Nick Cox <njcoxstata@gmail.com> wrote: > 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 > njcoxstata@gmail.com > > On 15 January 2014 21:12, David de Jong <davidcdejong@gmail.com> 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/ * * 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/