EDIT: a working example is provided further down
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?
regress write female read
Source | SS df MS Number of obs = 200
-------------+------------------------------ F( 2, 197) = 77.21
Model | 7856.32118 2 3928.16059 Prob > 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>|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
WORKING EXAMPLE: To illustrate my point, here is a small data sample that contains one categorical variable (pack
), one continuous variable (price
), and one dichotomous indicator (type
). After running a regression, I want to run a post estimation command (like predict
or a simple gen
) 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 pack
without converting pack
into multiple binary variables?
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??
generate
statement is not legal code. This is a broad question about basics:help estimates
is one place to start. – Nick Coxpredict
does not work in your example. – user4690969