title: Post-estimation commands in Stata _b[] for categorical variables
body: <p>EDIT: a working example is provided further down</p>
  
  <p>ORIGINAL: A post estimation command can be used to predict the value of the dependent variable. Here is an example, where you can type _b[_cons] + _b[x1]*1 + _b[x2] to get an actual value of Y. For most examples online on Stata, those values are either dummies or continuous. What if I have a categorical variable that is hard to manually transform into multiple dummies (like 52 weeks)? Can I preserve all my categorical variables and still run a post estimation command like the one below by telling Stata to pick the right value?</p>
  
  <pre><code>regress write female read
  
        Source |       SS       df       MS              Number of obs =     200
  -------------+------------------------------           F(  2,   197) =   77.21
         Model |  7856.32118     2  3928.16059           Prob &gt; F      =  0.0000
      Residual |  10022.5538   197  50.8759077           R-squared     =  0.4394
  -------------+------------------------------           Adj R-squared =  0.4337
         Total |   17878.875   199   89.843593           Root MSE      =  7.1327
  
  ------------------------------------------------------------------------------
         write |      Coef.   Std. Err.      t    P&gt;|t|     [95% Conf. Interval]
  -------------+----------------------------------------------------------------
        female |   5.486894   1.014261     5.41   0.000      3.48669    7.487098
          read |   .5658869   .0493849    11.46   0.000      .468496    .6632778
         _cons |   20.22837   2.713756     7.45   0.000     14.87663    25.58011
  ------------------------------------------------------------------------------
  and then ask
  
  gen _b[_cons] + _b[female]*1 + _b[read]*52   
  
  display _b[_cons] + _b[female]*1 + _b[read]*52
  55.141383
  </code></pre>
  
  <p>WORKING EXAMPLE: To illustrate my point, here is a small data sample that contains one categorical variable (<code>pack</code>), one continuous variable (<code>price</code>), and one dichotomous indicator (<code>type</code>). After running a regression, I want to run a post estimation command (like <code>predict</code> or a simple <code>gen</code>) that could generate predicted values. For that purpose, the only Stata codes I have found so far can only predict y using  continuous and binary variables but not categorical. Are you aware of a code that can solve the problem of including <code>pack</code> without converting <code>pack</code> into multiple binary variables? </p>
  
  <pre><code>clear
  input  units price pack type
  32 4 6 1
  2 20 18 1
  34 5 6 1
  32 8 6 0
  29 5 6 0
  5 10 12 0
  7 10 12 0
  1 10 18 0
  
  end
  
  reg units price type i.pack
  predict yhat
  *OR
  gen yhat=_b[_cons]+_b[_type]+....??pack??
  </code></pre>