Here's a toy version of my problem. Load the auto data, and break each auto's name into make and model.
sysuse auto.dta, clearNow I'd like to regress price on make, separately for foreign and domestic autos. I can't do it the obvious way
rename make make_model
split make_model, limit(2)
rename make_model1 make
rename make_model2 model
bysort foreign: reg price i.makebecause Stata won't accept strings as factor variables. (That always annoys me.) I need to encode the auto make as a number
encode make, gen(makenum)Now I can run my regression:
list makenum if make=="Datsun", nolabel /* Datsun is make number 7, but still labeled Datsun in output without the nolabel option */
bysort foreign: reg price i.makenumAnd the output looks very clear. For example, the coefficient for a Datsun (makenum==7) is -1986.
Now I wrap this up with statsby:
sort foreignNow I've got all my coefficients in a dataset in memory. But the way they're laid out is not very informative. The columns are labeled _stat_1, stat_2, etc. The coefficient for Datsun's is in _stat_7, which I might have guessed, but the standard error for Datsun is in _stat_31, which is impossible to guess unless you look at the variable labels.
statsby _b _se, by (foreign) clear: reg price i.makenum
I wasn't expecting this. I would think that statsby would put the coeffiecient and standard error for Datsun's (make 7) in columns called _b_make_7 and _se_make_7 (or really _b_Datsun and _se_Datsun, but maybe that's asking for too much).
Is there a way to get what I want out of statsby? Or a different command that I should use? Thanks.
Paul
.
0 Response to Store coefficients/SEs for factor variables, maybe using statsby
Post a Comment