title: Interaction syntax in Stata
body: <p>My question concerns the proper use of <code>#</code> versus <code>##</code> in Stata for interacting categorical and dependent variables. Here is the example I have in mind. </p>
  
  <p>To understand the marginal effect of <em>x</em> on <em>y</em> I ran an experiment with three treatments (<em>A, B, C)</em> on two types of subjects (<em>M, F</em>). To understand the pooled marginal effect (and supposing I satisfy all OLS criteria) I can run <code>reg y x</code>. However I also want to understand the marginal effect for each "species" in each "environment", or the interactions of <em>x</em> with treatment and types. </p>
  
  <p>Firstly, assuming <em>x</em> is continuous, is the proper syntax for estimating the pooled marginal effect <em>and</em> the treatment-type marginal effect</p>
  
  <pre><code>reg y x i.treatment#i.type#c.x
  </code></pre>
  
  <p>or </p>
  
  <pre><code>reg y i.treatment#i.type##c.x
  </code></pre>
  
  <p>or neither? </p>
  
  <p>Secondly, is the proper syntax for estimating just the treatment-type marginal effect</p>
  
  <pre><code>reg y i.treatment#i.type#c.x, noconstant
  </code></pre>
  
  <p>wherein the constant is dropped? If the constant is kept, does it represent the pooled response? </p>
  
  <p>Sorry if this is a rudimentary question, but after a few days reading I still struggle to grasp exactly what is the difference between <code>#</code> and <code>##</code>.  Many thanks in advance. </p>
  
  <p>Note: the data proposed are clearly a panel so the <code>xtreg</code> command is more appropriate. To keep things simple I just pretended the data were simpler. </p>
  
  <p><strong>Edit</strong>: Here is an example with a built-in Stata dataset. </p>
  
  <pre><code>    . reg price c.mpg##i.foreign
  
        Source |       SS       df       MS              Number of obs =      74
  -------------+------------------------------           F(  3,    70) =    9.48
         Model |   183435281     3  61145093.6           Prob &gt; F      =  0.0000
      Residual |   451630115    70  6451858.79           R-squared     =  0.2888
  -------------+------------------------------           Adj R-squared =  0.2584
         Total |   635065396    73  8699525.97           Root MSE      =  2540.1
  
  -------------------------------------------------------------------------------
          price |      Coef.   Std. Err.      t    P&gt;|t|     [95% Conf. Interval]
  --------------+----------------------------------------------------------------
            mpg |  -329.2551   74.98545    -4.39   0.000    -478.8088   -179.7013
      1.foreign |  -13.58741   2634.664    -0.01   0.996    -5268.258    5241.084
                |
  foreign#c.mpg |
             1  |   78.88826   112.4812     0.70   0.485    -145.4485     303.225
                |
          _cons |   12600.54   1527.888     8.25   0.000     9553.261    15647.81
  -------------------------------------------------------------------------------
  </code></pre>
  
  <p><code>mpg</code> and <code>1.foreign</code> capture, respectively, the marginal effect of a car's miles per gallon and whether it is foreign or domestic on price. <code>foreign#c.mpg</code> captures the interaction between the category dummy and the continuous <em>x</em> when the dummy is one (ie the car is foreign)? What then captures the interaction of domestic (dummy is zero) with <code>mpg</code>? </p>