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: A loop for each couple of variables (instead of for each variable)


From   Fabien Bertho <fabien.bertho@sciences-po.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: A loop for each couple of variables (instead of for each variable)
Date   Mon, 12 Sep 2011 14:31:10 +0200 (CEST)

Yes, it is what I needed.
Thank you very much for your help.

Fabien


> ----------------------------------------
> From: Nick Cox <njcoxstata@gmail.com>
> Sent: Mon Sep 12 13:11:47 CEST 2011
> To: <statalist@hsphsun2.harvard.edu>
> Subject: Re: st: A loop for each couple of variables (instead of for each variable)
> 
> 
> I don't know what # and & are doing here.
> 
> You can do this:
> 
> foreach x in "a b" "c d" "e f" {
> 
>       <stuff> `x'
> 
> }
> 
> If this is not what you want, you may need to repost a much clearer question.
> 
> Nick
> 
> On Mon, Sep 12, 2011 at 11:53 AM, Fabien Bertho
> <fabien.bertho@sciences-po.org> wrote:
> > Hi,
> >
> > I created a loop in order to estimate various specifications of my model
> >
> > foreach variables in ""var_1 var_2 {
> > reg dep_var control_var `variables&#8217;
> > }
> >
> > Now, I would like to run this loop not for two variables but for two locals that comprises two variables. I tried the following code.
> >
> > local local_1 &#8220;var_1 var_2&#8221;
> > local local_2 &#8220;var_3 var_4&#8221;
> > foreach local_variables in ""`local_1&#8217; ` var_2&#8217; {
> > reg dep_var control_var `local_variables&#8217;
> > }
> >
> > But it does not work because during the loop Stata splits my local into two variables&#8230;
> > Do you think that it is possible to estimate a loop for each couple of variables instead of for each variable? How can I do this?
> >
> *
> *   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/


--------------------------------------------------------------------------
Tous les courriers électroniques émis depuis la messagerie
de Sciences Po doivent respecter des conditions d'usages.
Pour les consulter rendez-vous sur
http://www.ressources-numeriques.sciences-po.fr/confidentialite_courriel.htm

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