Announcement

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

  • How to plot the below graphs after quantile regression?

    Please could anyone tell how to plots the same graphs after quantile regression? I have tried to plots with "grqreg" command but i got different graphs. Please help me thanks.

    Click image for larger version

Name:	Untitled.jpg
Views:	3
Size:	129.2 KB
ID:	1483206

  • #2

    Code:
    sysuse auto, clear
    sqreg price weight length foreign, quantile(.1 .2 .3 .4 .5 .6 .7 .8 .9) reps(100)
    
    preserve
    gen q = _n*10 in 1/9
    
    foreach var of varlist weight length foreign {
        gen _b_`var'  = .
        gen _lb_`var' = .
        gen _ub_`var' = .
    
        local i = 1
        foreach q of numlist 10(10)90 {
            replace _b_`var' = _b[q`q':`var'] in `i'
            replace _lb_`var' = _b[q`q':`var'] - _se[q`q':`var']*invnormal(.975) in `i'
            replace _ub_`var' = _b[q`q':`var'] + _se[q`q':`var']*invnormal(.975) in `i++'
        }
    }
    keep q _b_* _lb_* _ub_*
    keep in 1/9
    reshape long _b_ _lb_ _ub_, i(q) j(var) string
    set scheme s1color
    twoway rarea _lb_ _ub_ q, astyle(ci) yline(0) acolor(%90) || ///
       line _b_ q,                                               ///
       by(var, yrescale xrescale note("") legend(at(4) pos(0)))  ///
       legend(order(2 "effect"                                   ///      
                    1 "95% confidence" "interval")               ///
              cols(1))                                           ///
       ytitle(effect on percentile of price)                       ///
       ylab(,angle(0) format(%7.0gc))                            ///    
       xlab(10(10)90) xtitle(percentile of price)
    restore
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	86.6 KB
ID:	1483214
    Last edited by Maarten Buis; 12 Feb 2019, 02:12.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks but i found the followings errors.

      . twoway rarea _lb_ _ub_ q, astyle(ci) yline(0) acolor(%90) || ///
      / / / is not a twoway plot type
      r(198);

      .
      . line _b_ q, ///
      option / not allowed
      r(198);

      .
      . by(var, yrescale xrescale note("") legend(at(4) pos(0))) ///
      : required
      r(100);

      .
      . legend(order(2 "effect" ///
      command legend is unrecognized
      r(199);

      .
      . 1 "95% confidence" "interval") ///
      1 is not a valid command name
      r(199);

      .
      . cols(1)) ///
      command cols is unrecognized
      r(199);

      .
      . ytitle(effect on percentile of price) ///
      command ytitle is unrecognized
      r(199);

      .
      . ylab(,angle(0) format(%7.0gc)) ///
      command ylab is unrecognized
      r(199);

      .
      . xlab(10(10)90) xtitle(percentile of price)
      command xlab is unrecognized
      r(199);

      Comment


      • #4
        Originally posted by Zeeshan Fareed View Post
        Thanks but i found the followings errors.

        . twoway rarea _lb_ _ub_ q, astyle(ci) yline(0) acolor(%90) || ///
        / / / is not a twoway plot type
        r(198);

        .
        . line _b_ q, ///
        option / not allowed
        r(198);

        .
        . by(var, yrescale xrescale note("") legend(at(4) pos(0))) ///
        : required
        r(100);

        .
        . legend(order(2 "effect" ///
        command legend is unrecognized
        r(199);

        .
        . 1 "95% confidence" "interval") ///
        1 is not a valid command name
        r(199);

        .
        . cols(1)) ///
        command cols is unrecognized
        r(199);

        .
        . ytitle(effect on percentile of price) ///
        command ytitle is unrecognized
        r(199);

        .
        . ylab(,angle(0) format(%7.0gc)) ///
        command ylab is unrecognized
        r(199);

        .
        . xlab(10(10)90) xtitle(percentile of price)
        command xlab is unrecognized
        r(199);
        Zeeshan,

        You have to copy Maarten's code into a do file, then execute the whole block. It doesn't work if you copy and paste line by line.

        /// is a line break. That tells Stata that the code continues on the next line in a do file, but it's only recognized in do files.
        Please use the code delimiters to show code and results - use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

        Please use the command -dataex- to show a representative sample of data; it is installed already if you have Stata 14.2 or 15.1, else you can install it by typing

        Code:
        ssc install dataex

        Comment


        • #5
          Thanks all, i have done.

          Comment

          Working...
          X