Running regressions with similar sets of variables

Quite often we run variations on regressions, including or excluding (sets of) variables. Copy-pasting the regression and eliminating the variables to be excluded is one way, but given that we speak of sets of variables why not use locals to do the work for you:

local actgeb="a_sales a_rd a_prod a_plan a_kwal a_mana"
local agegrp="age_c1 age_c2 age_c4 age_c5 age_c6 age_c7"
local educat="edu_c1 edu_c2 edu_c3 edu_c4 edu_c5 edu_c7"
local tengrp="tenure_c1 tenure_c3 tenure_c4 tenure_c5 "
local layer="layer_c2 layer_c3 layer_c4 layer_c5 layer_c6 "
local eval="eval_c1 eval_c3 eval_c4"


stset date, origin(time 13223) exit(time 14340) id(birc)
stcox `agegrp' `tengrp' `educat' `actgeb' `layer', bases(s)
stcox `tengrp' `educat' `actgeb' `layer', bases(s)
[...]

One caveat: don’t put to much variabels in one local … if it gets too long it just leaves out the last part.

One thought on “Running regressions with similar sets of variables”

  1. This works fine while running the do-file. But when the do-file has run, the locals are lost. So after running the do-file you could estimate an alternative model such as:
    stcox `tengrp’ `educat’ `actgeb’, bases(s)
    because the locals are unknown.
    To be able to use a list regressors in a more interactive way, you should use globals rather than locals. It looks like this:

    global actgeb “a_sales a_rd a_prod a_plan a_kwal a_mana”
    global agegrp “age_c1 age_c2 age_c4 age_c5 age_c6 age_c7”
    global educat “edu_c1 edu_c2 edu_c3 edu_c4 edu_c5 edu_c7”
    global tengrp “tenure_c1 tenure_c3 tenure_c4 tenure_c5”
    global layer “layer_c2 layer_c3 layer_c4 layer_c5 layer_c6”
    global eval “eval_c1 eval_c3 eval_c4”

    stset date, origin(time 13223) exit(time 14340) id(birc)
    stcox $agegrp $tengrp $educat $actgeb $layer’, bases(s)
    […]

    All globals are kept in memory after running the do-file and can be refered to later.

Leave a Reply