Announcement

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

  • How to plot two quantile regression coefficients in one graph

    I want to plot quantile regression coefficients on Stata after running the regression separately for urban and rural households. I used the command "grqreg" which plots the coefficients across the distribution, but it is for each regression separately. I want to compare urban to rural households, so a two-way graph would be useful but this command does not let me do it. Is there any other code that will allow me to do this?

    thank you

  • #2
    There is here no code or data to indicate exactly what you did. Nevertheless this may help.

    I doubt that you just want to plot the coefficients, as that's at most two or four values, depending on what you include. But if so, search for Ben Jann's coefplot (SJ).

    I guess that you mean plotting the lines defined by the coefficients.

    The essence of this example is that as Stata gives you the coefficients of the regression, it's just a matter of retrieving them from the saved results, here in the form _b. You should want to see the data too.

    If this isn't what you want, please rephrase your question in terms of data you give or a mutually accessible dataset.

    Code:
    clear
    sysuse auto
    set scheme s1color
    
    gen gptm = 1000/mpg
    label var gptm "gallons / 1000 miles"
    
    qreg gptm weight if foreign
    local slopef = _b[weight]
    local interf = _b[_cons]
    
    qreg gptm weight if !foreign
    local sloped = _b[weight]
    local interd = _b[_cons]
    
    separate gptm, by(foreign) veryshortlabel
    separate weight, by(foreign)
     
    scatter gptm? weight, mc(red blue) ms(Oh +)||           ///
    function `interd' + (`sloped' * x), ra(weight0) lcolor(red) || ///
    function `interf' + (`slopef' * x), ra(weight1) lcolor(blue) ///
    ytitle(`: var label gptm') xtitle(`: var label weight') ///
    legend(order(2 1) col(1) pos(11) ring(0)) yla(, ang(h))
    Click image for larger version

Name:	qreg.png
Views:	1
Size:	12.3 KB
ID:	1299871

    Comment


    • #3
      Please read advice in the FAQ on references (Section 13) and especially on how to ask questions, including giving your code (Section 12). The latter specifically advises against showing graphs as photographs: include graphs as .png attachments. .

      Comment

      Working...
      X