Quantcast

interaction variables

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

interaction variables

daniele.curzi
This post has NOT been accepted by the mailing list yet.
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!

Thanks for your help
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: interaction variables

ray.chang
This post has NOT been accepted by the mailing list yet.
It would be basic; you might learn a little bit about programming:

Make a do file like this and execute it:

forvalues i = 1/50 {
   gen cy`i'=country`i'*years
}


Make sure that it is `' not ' '.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: interaction variables

paul mwaniki
This post has NOT been accepted by the mailing list yet.
This post was updated on .
The easiest way is to use:
regress outcome i.country##c.years
where i. tell stata that that is a factor and c. tell stata that that is a continuous variable.
or if you just want to create the dummies:
xi i.country|price
Loading...