benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
71 stars 18 forks source link

Default unary operator and Interaction labels #35

Closed ozak closed 2 years ago

ozak commented 2 years ago

Hi. Is there a way of changing the default labels assigned to unary operators (i.X) and interaction terms (i.X1##i.X2)? E.g., if I run

sysuse auto, clear
gen efficient = 1 - (mpg<23)
label var efficient "Efficient"
eststo clear
eststo: reg price i.efficient##i.foreign, r
esttab, nobaselevels label

I get

image

and I'd like to just have Efficient instead of efficient=1. Are the only options to encode the variable, as in the case of foreign? Or relabel in the esttab command using the varlabels option (which would require labeling each element)? Is there no option to just use the label of the variable and not add the =1?

NilsEnevoldsen commented 2 years ago

Another option is defining a value label.

sysuse auto, clear
gen efficient = 1 - (mpg<23)
label var efficient "Efficient" // Not used
label define efficient 1 "Efficient" 0 "Inefficient"
label val efficient efficient
eststo clear
eststo: reg price i.efficient##i.foreign, r
esttab, nobaselevels label
dreistein543 commented 2 years ago

since the key variables you use are binary, maybe you can treat them as continuous variables and type:

label var efficient “Efficient”
label var foreign “Foreign”
eststo: reg price c.efficient##c.foreign
esttab, label

just notice that the key interaction is the 1 x 1 item

benjann commented 2 years ago

As Nils correctly noted, esttab will use the value label if a value label is defined; otherwise the =1 variant is used. You can also change the symbol used in interaction terms using option interaction(). Example:

sysuse auto, clear
gen efficient = 1 - (mpg<23)
label var efficient "Efficient" // Not used
label define efficient 1 "Efficient" 0 "Inefficient"
label val efficient efficient
eststo clear
eststo: reg price i.efficient##i.foreign, r
esttab, nobaselevels label interaction(" X ")

If you want a complety different label for the interaction term, i.e. not one that is constructed based on the labels of the involved variables, then your only possibility is to manually assign a label. Example:

esttab, nobaselevels label varlabel(1.efficient#1.foreign "Some interaction!")

ben

ozak commented 2 years ago

Thanks for the help.