Announcement

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

  • glcurve

    Dear All,
    I'm exploring 5-year stacked dataset. Trying to compare distribution over this period using absolute Lorenz curves. I used
    Code:
    glcurve income , split by(year)
    . I got a graph with this but without the line of perfect equality (similar to 45-degree line). Any help on how to add this?

    Thanks,
    Dapel
    Last edited by Zuhumnan Dapel; 08 Apr 2015, 09:23.

  • #2
    Please explain where user-written programs you refer to come from, as requested in the FAQ Advice.

    glcurve is from SJ/SSC.

    This is a documented example in the help. Use the option

    Code:
    plot(function equality = x)
    Last edited by Nick Cox; 08 Apr 2015, 10:27.

    Comment


    • #3
      As the help file for glcurve states:
      The graphs drawn by glcurve are relatively basic. For graphs with full user control over formatting and
      labelling, users are recommended to use glcurve to generate the ordinates of the graph required using the
      pvar(newvarname) and glvar(newvarname) options, and then to draw the graph using graph twoway.
      This is how you can add things such as the line of "perfect equality".
      You can find illustrative code in, for example, the appendix to https://www.iser.essex.ac.uk/files/i...rs/2005-05.pdf
      NB As per Forum FAQ, you should say where you found user-written programs. (glcurve is on SSC.)

      Comment


      • #4
        Thanks Dr Cox.

        Here is are some
        Code:
        glcurve pce [aw = popwt2] , by(year) split pvar(prl) glvar(rl) lorenz nograph 
        lab var rl_1980 "1980"
        lab var rl_1985 "1985"
        lab var rl_1992 "1992"
        lab var rl_1996 "1996"
        lab var rl_2004 "2004"
        lab var rl_2010 "2010"
        
        lab var prl"Cumulative population share"
        sort prl
        graph twoway(line rl_1980 prl, yaxis(1 2)) ///
        (line rl_1985 prl, yaxis(1 2)) ///
        (line rl_1992 prl, yaxis(1 2)) ///
        (line rl_1996 prl, yaxis(1 2)) ///
        (line rl_2004 prl, yaxis(1 2)) ///
        (line rl_2010 prl, yaxis(1 2)) ///
        (function y = pce, range(0 1) yaxis(1 2))///
        ,aspect(1) xtitle("Cumulativepopulation share, p") ///
        ytitle("Incomeshare of poorest 100p%", axis(1)) ytitle(" ",axis(2)) ///
        legend(label(1 "1980") label(2 "1985") label(3 "1992") label(4 "1996") label(5 "2004") label(6 "2010")label(7 "Equality") ///
        region(lstyle(none))) saving(rl80_10, replace)
        .

        I got
        Code:
        . graph twoway(line rl_1980 prl, yaxis(1 2)) ///
        > (line rl_1985 prl, yaxis(1 2)) ///
        > (line rl_1992 prl, yaxis(1 2)) ///
        > (line rl_1996 prl, yaxis(1 2)) ///
        > (line rl_2004 prl, yaxis(1 2)) ///
        > (line rl_2010 prl, yaxis(1 2)) ///
        > (function y = pce, range(0 1) yaxis(1 2))///
        ) required
        r(100);
        
        end of do-file
        
        r(100);
        . Still needing some help

        Comment


        • #5
          Thank Prof Jenkins. I have followed this in post #4. Still needing some help

          Comment


          • #6
            I guess Stata is getting confused. The command twoway function should make reference to a generic x.

            It's incidental, but you can have several y variables in a line plot.

            Comment


            • #7
              Dear Dr Cox, I'm yet to get that

              Comment


              • #8
                You are asking readers to look at diagnose detailed errors in code when we don't have access to your data -- which is quite a Big Ask. In this sort of situation (relatively lengthy graph code), it is usually best to add each line one at time (or remove selected lines) in order to isolate where the problem(s) lie. In your particular case, look at the line
                (function y = pce, range(0 1) yaxis(1 2))///
                I suspect that you require a space after the last ")" and before the "///".

                Comment


                • #9
                  Thank you Prof Jenkins. I have confirmed that
                  Code:
                  glcurve pce [aw = popwt2] , by(year) split pvar(prl) glvar(rl) lorenz nograph 
                  lab var rl_1980 "1980"
                  lab var rl_1985 "1985"
                  lab var rl_1992 "1992"
                  lab var rl_1996 "1996"
                  lab var rl_2004 "2004"
                  lab var rl_2010 "2010"
                  
                  lab var prl"Cumulative population share"
                  sort prl
                  graph twoway(line rl_1980 prl, yaxis(1 2)) ///
                  (line rl_1985 prl, yaxis(1 2)) ///
                  (line rl_1992 prl, yaxis(1 2)) ///
                  (line rl_1996 prl, yaxis(1 2)) ///
                  (line rl_2004 prl, yaxis(1 2)) ///
                  (line rl_2010 prl, yaxis(1 2)) ///
                  (function y = pce, range(0 1) yaxis(1 2) ) ///
                  ,aspect(1) xtitle("Cumulativepopulation share, p") ///
                  ytitle("Incomeshare of poorest 100p%", axis(1)) ytitle(" ",axis(2)) ///
                  legend(label(1 "1980") label(2 "1985") label(3 "1992") label(4 "1996") label(5 "2004") label(6 "2010")label(7 "Equality") ///
                  region(lstyle(none))) saving(rl80_10, replace)
                  is OK.

                  The problem is with the last command line
                  Code:
                  region(lstyle(none))) saving(rl80_10, replace)
                  I still find it difficult to resolve this.

                  Comment


                  • #10
                    The specific problem here is that your parentheses in

                    Code:
                      
                    region(lstyle(none)))
                    don't match as you have two (( and three ))).

                    We've already made suggestions to simplify your line call and correct the call to function which you haven't yet implemented. With some further simplifications and corrections, consider something like this:

                    Code:
                    twoway function y = x, range(0 1)  ///
                    || line rl_1980 rl_1985 r1_1992 r1_1996 r1_2004 r1_2010 prl, yaxis(1 2) ///
                    aspect(1) xtitle("Cumulative population share, p") ///
                    ytitle("Income share of poorest 100p%", axis(1)) ytitle(" ",axis(2)) ///
                    legend(order(2 "1980" 3 "1985" 4 "1992" 5 "1996" 6 "2004" 7 "2010" 1 "Equality") ///
                    region(lstyle(none)) saving(rl80_10, replace)
                    Last edited by Nick Cox; 09 Apr 2015, 05:45.

                    Comment


                    • #11
                      Thanks Dr Cox. Your suggest worked but I added ) to
                      Code:
                       region(lstyle(none))) saving(rl80_103, replace)
                      so that we now have
                      Code:
                      glcurve pce [aw = popwt2] , by(year) split pvar(prl) glvar(rl) lorenz nograph
                      lab var rl_1980 "1980"
                      lab var rl_1985 "1985"
                      lab var rl_1992 "1992"
                      lab var rl_1996 "1996"
                      lab var rl_2004 "2004"
                      lab var rl_2010 "2010"
                      
                      twoway function y = x, range(0 1)  ///
                      || line rl_1980 rl_1985 rl_1992 rl_1996 rl_2004 rl_2010 prl, yaxis(1 2) ///
                      aspect(1) xtitle("Cumulative population share, p") ///
                      ytitle("Income share of poorest 100p%", axis(1)) ytitle(" ",axis(2)) ///
                      legend(order(2 "1980" 3 "1985" 4 "1992" 5 "1996" 6 "2004" 7 "2010" 1 "Equality") ///
                      region(lstyle(none))) saving(rl80_103, replace)
                      Dapel

                      Comment


                      • #12
                        I see now that region() qualifies the legend(). I guessed wrongly that you wanted otherwise. In that case, there must have been some other mistake that has been fixed now.
                        Last edited by Nick Cox; 09 Apr 2015, 07:22.

                        Comment


                        • #13
                          Dear All,
                          How do I increase the with between the curves in such away that the trend being depicted will be very clear?

                          Thanks,
                          Dapel

                          Comment

                          Working...
                          X