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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: foreach for interaction term


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: foreach for interaction term
Date   Tue, 24 May 2011 16:27:41 +0200

On Tue, May 24, 2011 at 4:21 PM, Barbara Engels <engels.ba@gmail.com> wrote:
> well, now i modified it again, to make it more understandable for me and for stata.
>
>  foreach `x' of ger_ims bel_ims chin_ims usa_ims uk_ims it_ims switz_ims {
>  2.   ge foreignbrd*=`X'*(*brd)
>  3.  }
> invalid syntax
> r(198);
>
> I want it to create values containing the product of import share and R&D stock (=foreignbrd) of each country for each year.
>
> Is that understandable? I 'm a little confused.

There are a great many things wrong here:

In your code -foreach- creates a local with a name stored in the local
x. This is (probably) wrong. Instead you would (probably) want to say
foreach x of ...

You need to specify what kind of list you specify when you say -of- in
-foreach-, alternatively you can say -in-.

You cannot interchange `x' with `X', the two are different things.

you cannot use wildcards this way, instead you probably want a nested loop

 foreach x of varlist ger_ims bel_ims chin_ims usa_ims uk_ims it_ims switz_ims {
    foreach y of varlist *brd {
        ge `x'_X_`y' =`x'*`y'
    }
}

-- Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------

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