Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Foreach loop for subsequent variables


From   Dmitriy Glumov <glumovdm@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Foreach loop for subsequent variables
Date   Wed, 2 Nov 2011 09:30:21 -0400

Daniel, Nick, and Matthew,

Thank you for providing solutions, I have tried all three and they
worked beautifully, saving a lot of time. Moreover, all of these can
serve as helpful templates for the future, when I (and other users)
come across a similar problem. Again, thank you.

Dmitriy

On Tue, Nov 1, 2011 at 1:38 PM, daniel klein
<klein.daniel.81@googlemail.com> wrote:
> Nick,
>
> thanks for sharing this clever usage of -tokenize-. This might save
> some typing in similar situations.
>
> Here is another way, that might be faster, given the repeated useage
> of -preserve- and -restore- in the codes given by Matt and Nick.
>
> unab varlist : *
> tokenize `varlist'
>
> forv j = 1(2)897 {
>        use ``j'' ``= `j' + 1'' using <filename>
>        save `j'2
> }
>
> Best
> Daniel
>
> --
> Matthew's code should work. This is an alternative:
>
> unab varlist : *
> tokenize `varlist'
> forvalues i = 1(2)897 {
>        preserve
>        local j = `i' + 1
>        keep ``i'' ``j''
>        save `i'2
>        restore
> }
>
> But there is no important reason to use this code rather than Matthew's.
> *
> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index