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: interaction variables


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: interaction variables
Date   Fri, 15 Apr 2011 17:25:45 +0100

In terms of travelling from where you are now,

forval j = 1/50 {
      gen cy`j' = country`j' * year
}

See also -help forvalues- or

SJ-2-2  pr0005  . . . . . .  Speaking Stata:  How to face lists with fortitude
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/02   SJ 2(2):202--222                                 (no commands)
        demonstrates the usefulness of for, foreach, forvalues, and
        local macros for interactive (non programming) tasks

The last is available at
http://www.stata-journal.com/sjpdf.html?articlenum=pr0005


On Fri, Apr 15, 2011 at 5:20 PM, daniele.curzi <[email protected]> wrote:
> Dear Stata Members, I have to generate interaction variables between a
> country dummy and a time variable!
>
> I have a dataset with 50 countries. So using the tabulate command I get 50
> dummy variables (country1, country2,....country 50). Now I want to multiply
> all these variables for a time variable! In this case I will generate 50 new
> variables!
>
> To do that, I can multiply each country dummy for the time variable.
>
> gen cy1=country1*year
>
> gen cy2=country2*years
>
> ....
>
> gen cy50=country50*years
>
> I was wondering if there exist any command to make this in a faster way!
*
*   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