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: foreach for interaction term
From
Neil Shephard <[email protected]>
To
[email protected]
Subject
Re: st: foreach for interaction term
Date
Tue, 24 May 2011 15:23:43 +0100
On Tue, May 24, 2011 at 3:21 PM, Barbara Engels <[email protected]> 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.
You've misunderstood how to use loops, you don't put ` and ' around
the local you wish to define to be used in the loop, nor can you
change the case within your loop. Legal syntax for the above would
be...
Break this problem down, you have multiple countries and for each you
have two variables. You want to construct a new variable for each
country that is the product of each of the others.
Thus I would start by...
1. Looping over each of the countries.
2. For each country I'm looping over generate the interaction term
So something like...
foreach x of ger bel chin usa uk it switz {
gen interaction_`x' = `x'_ims * `x'brd
}
Although if you're using Stata >11.0 (which you haven't told us, see
comments in the Statalist FAQ) then you might want to look at the -man
fvvarlist- for a much easier way of using interactions in subsequent
analyses you wish to perform.
Neil
--
“Truth in science can be defined as the working hypothesis best suited
to open the way to the next better one.” - Konrad Lorenz
Email - [email protected]
Website - http://kimura.no-ip.org/
Photos - http://www.flickr.com/photos/slackline/
*
* 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/