How to export regression model results and label by "today" in Stata?

Viewed 224

I run a series of regression models (almost everyday). I manually keep track of my results by labeling exported regression results with a date (year-month-day format). How can this be automated in Stata (with outreg2 to Word)? Here is a minimal working example:

* load data
use http://www.stata-press.com/data/r13/nlswork

* regression 
reg ln_wage c.age c.wks_u i.race i.union 

* export results in word document in a file appended by "today"/date
outreg2 using "C:\PATH\Results\model_1_2020_08_21.doc", word 
1 Answers

Today's date is accessible as a c-class result. Then you just need to format that as desired.

Here is how to get a local macro automatically:

. local wanted : di %tdCY!_N!_D daily(c(current_date), "DMY")

. di "`wanted'"
2020_08_21

So, you apply that like this

. local filename "C:\whatever\model_1_`wanted'.doc" 

with the understanding that (e.g.) the model number might vary too.

Related