Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Ulrich Kohler <kohler@wzb.eu> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Questions about interaction terms using #. |
Date | Wed, 09 Nov 2011 09:10:31 +0100 |
Am Dienstag, den 08.11.2011, 20:35 +0000 schrieb YangSP: > Dear Statalister, > > I need to generate interaction terms using exporter and year in a standard gravity model. > > > For example, my data is listed as follows, > year exporter importer volume GDP_exporter GDP_importer Distance ... ... > 1995 A B 1000 100 500 xxx > 1996 A B 2000 200 600 xxx > 1997 A B 3000 300 700 xxx > 1998... > > > My two questions are: > > Q1: What is the difference between "i.exporter*year" and "exporter#year"? I thought they were the same thing, but they are not because of the different resluts from them. Someone who can tell me what does each of them exactly mean. I think Stata interprets the asterisk in "i.exporter*year" as a wild card character, i.e. you ask for creating dummy variables for all variables whose names start with "exporter" and end with "year". "exporter#year", forms all twoway interactions between dummy variables of the variables exporter and year. It is shorthand for "i.exporter#i.year". Perhaps want you really want is "i.exporter##i.year", which forms all the interactions _and_ dummies for the constituent variables (aka main effects). > > Q2: If a command, e.g. qreg, does not support "exporter#year", how can I generate the interaction terms using "gen"? See help -xi- or use first principles: . sysuse auto, clear . tab rep78, gen(rep78_) . tab for, gen(for_) . foreach var1 of varlist for_* { . foreach var2 of varlist rep78_* { . gen `var1'`var2' = `var1'*`var2' . } .} * * 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/