Announcement

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

  • coefplot subgraphs by coefficients: how to loop subgraphs?

    Hi Statalist,

    I was referring to the coefplot trying to make subgraphs like this (below are example codes from http://repec.sowi.unibe.ch/stata/coe...started.html):
    Code:
    sysuse auto, clear
    forv i = 3/5 {    
    quietly regress price mpg headroom weight turn if rep78==`i'    
    estimate store rep78_`i' }
    coefplot rep78_3 || rep78_4 || rep78_5, drop(_cons) xline(0) ///    
    bycoefs byopts(xrescale)

    For the last line of command, "coefplot rep78_3 || rep78_4 || rep78_5, XXX", I wonder how I can write a loop over consecutive numbers (in this case, looping 3, 4, 5 for rep78_). I tried multiple ways and could not get it work, including using wildcards (*) or something like this (which did not work):
    Code:
    coefplot ///
    forvalues i=3/5 {
    rep78_`i' || ///
    }
    I'd greatly appreciate if anyone could point me to a right direction to solve this.. Thanks in advance!

    Yingyi

  • #2
    Code:
    local plots rep78_3
    forval i=4/5{
        local plots "`plots' || rep78_`i'"
    }
    di "`plots'"
    coefplot `plots', drop(_cons) xline(0) bycoefs byopts(xrescale)
    Res.:

    Code:
    . di "`plots'"
    rep78_3 || rep78_4 || rep78_5

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      local plots rep78_3
      forval i=4/5{
      local plots "`plots' || rep78_`i'"
      }
      di "`plots'"
      coefplot `plots', drop(_cons) xline(0) bycoefs byopts(xrescale)
      Res.:

      Code:
      . di "`plots'"
      rep78_3 || rep78_4 || rep78_5
      Thanks Andrew! This works perfectly!

      Comment

      Working...
      X