Stata: combining regression results with other res

2019-09-06 20:02发布

问题:

I am trying to replicate some results from a study. therefore often i need to compare my regression results with results from the study that i'm trying to replicate. I have been manually combining my esttab results with the study results in excel. this however is tedious since i'm working with lot of variables. I was wondering whether there is a way to store the study results and then calling them to go next to my regression results. I tried storing them as scalars and calling them using estout however this puts the stored scalars below the regression results. i would prefer to have them side by side as another column.

Example:

Reference study results are

var b
x  2.1
z  4.2

I entered these into Stata

estadd scalar x=2.1
estadd scalar z=4.2

My regression is

eststore: reg y x z
estout, stats(x,z)

but when i do this i get a table like this

var        b
my reg x   5.3
my reg z   2.3
scalar x   2.1
scalar z   4.2

But I would want the results like this

var        b      scalar b
my reg x   5.3     2.1
my reg z   2.3     4.2

回答1:

The following might help. Find comments inline.

clear 
set more off

*----- example data -----

sysuse auto
keep price weight mpg

*----- what you want -----

//regress and store
reg price weight mpg 
eststo m1

// create matrix of "scalars"
matrix w = (2.1 , 2.4 , 3.2) 

// rename matrix columns to coincide with those of regression
mat colnames w = weight mpg _cons 

// add
estadd matrix w

// print
estout m1, cells("b w")