Bookmark and Share

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: construct a loop


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: construct a loop
Date   Sun, 20 Feb 2011 08:51:32 +0000

Well, your solution then gets more complicated. The thread has already
shown that you can nest loops. Also see

FAQ     . . . . . . . . . . Making foreach go through all values of a variable
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        8/05    Is there a way to tell Stata to try all values of a
                particular variable in a foreach statement without
                specifying them?
                http://www.stata.com/support/faqs/data/foreach.html

Nick

On Sat, Feb 19, 2011 at 8:48 PM, Nikolaos Pandis <[email protected]> wrote:

> Thank you all this looks great!
>
> Now what if I would like to run the same commands for more than just the varX variable?
> What if the variables have variable number of category levels?
>
> Many thanks,
>
> Nick
>
>
>
> --- On Sat, 2/19/11, Nick Cox <[email protected]> wrote:
>
>> From: Nick Cox <[email protected]>
>> Subject: Re: st: construct a loop
>> To: [email protected]
>> Date: Saturday, February 19, 2011, 9:14 PM
>> Here is another way to do it.
>>
>> foreach p in "1 0" "2 0" "3 0" "2 1" "3 1" "3 2" {
>> tokenize "`p'"
>> stmh varX, c(`1' , `2')
>> }
>>
>> Nick
>>
>> On Sat, Feb 19, 2011 at 12:03 PM, Nikolaos Pandis <[email protected]>
>> wrote:
>>
>> > I would like to run the following commands using the 4
>> level varX:
>> > stmh varX,c(1,0)
>> > stmh varX,c(2,0)
>> > stmh varX,c(3,0)
>> > stmh varX,c(2,1)
>> > stmh varX,c(3,1)
>> > stmh varx,c(3,2)
>> >
>> > I would grateful if someone would help me construct a
>> loop to run all the above commands.
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index