Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating coefplots based on looped regressions

    Hi,

    I wanted to know if there is a way to create coefplots using a loop. The loop keeps replacing the graph and ends up showing the last graph. Is there a way to put a local condition and make it run?

    Code:
    global controls age agesq i.caste urban i.household_expenditure_quintile i.education
    
    foreach v of varlist contraceptive_use ideal_children AIDS_Knowledge {
    qui areg `v' interaction $controls [pweight=WT], absorb(HHID) vce(cl HHID)
    coefplot, keep(interaction age agesq *.caste urban) xline(0)  xlab(, nogrid) grid(none)
    }

  • #2
    First, for the benefit of others: coefplot is a community-contributed command, available from SSC.

    Second, coefplot allows many twoway options (see help twoway_options) , including name.

    When a name is not specified, most graphing commands (including coefplot) assume the name should be Graph, and every new graph that is plotted replaces an old one with that name.

    To keep multiple graphs in memory, you need to give each a different name. So maybe do this:

    Code:
    global controls age agesq i.caste urban i.household_expenditure_quintile i.education
    
    foreach v of varlist contraceptive_use ideal_children AIDS_Knowledge {
    qui areg `v' interaction $controls [pweight=WT], absorb(HHID) vce(cl HHID)
    coefplot, keep(interaction age agesq *.caste urban) xline(0)  xlab(, nogrid) grid(none) name(graph_`v', replace)
    }
    See also
    Code:
    help name_option

    Comment

    Working...
    X