Announcement

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

  • Axis and lines on graph not showing

    Dear Statalist:

    I cannot get two lines to show on my twoway graph: The top line of the x-axis where I added two area graphs and a vertical line (at 1990.6) where the two area graphs meet.
    (Thanks to Nick Cox I figured out everything else - thank you so much, Nick!)

    I am using Stata 15.1 .

    Here is my code:

    # delimit ;
    sort yob east;

    statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), by(yob east) clear: ci means smoking;
    label variable mean "Smoking Rates";
    gen upper = 0.8;

    sort yob;

    local area upper y if inrange(y, 1989.8, 1990.6), bcolor(bluishgray) base(0);
    local area2 upper y if inrange(y, 1990, 1993), bcolor(ltbluishgray) base(0);
    local scatter1 mean yob if east==0, connect(direct) lcolor(black) mcolor(black) msymbol(triangle);
    local scatter2 mean yob if east==1, connect(direct) lcolor(blue) mcolor(blue) xlabel(#15) xla(, ang(45)) plotregion(margin(zero));

    twoway area `area' xline(1989.8 1993, lcolor(black) lpattern(dash)) ytitle("Smoking Rates")
    || area `area2' xline(1990.6, lcolor(black) lpattern(dash))
    || rcap ub lb yob if east==0, lcolor(black) || scatter `scatter1'
    ||rcap ub lb yob if east==1, lcolor(blue)
    || scatter `scatter2' text(.12 1990.1 "Crossing" .12 1991.8 "In Transition", orient(vertical) alignment(top) color(navy)) text(.33 1999 "East" 0.167 1999 "West") legend(off) xscale(range(1994 2000)) xlabel(1984/1998);



    I tried adding a horizontal line on top with: yline(1984 2000, lcolor(black) lstyle(foreground)) , but that did not do anything.

    (I tried to upload the graph but it does not show on the preview, I hope it shows.)

  • #2
    See https://www.statalist.org/forums/for...oway-area-plot

    Comment


    • #3
      I think this should work:

      Click image for larger version

Name:	for_statalist_post.png
Views:	1
Size:	269.5 KB
ID:	1613022

      Comment


      • #4
        Thank you, Andrew. I have been trying to figure out how to do this with either twoway scatteri or twoway dropline, but I have not figured out how to add these commands to the graph I already have.
        I would be grateful for some pointers.


        Comment


        • #5
          Can you post a data example using dataex?

          Comment


          • #6
            Thank you!

            This is my data after doing statsby.

            Please let me know if this is not what you meant.


            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input float(yob east mean ub lb upper)
              1984 0  .3827161  .4228443  .3425878 .8
              1984 1 .44155845  .5060731  .3770438 .8
              1985 0  .4070022  .4522133  .3617911 .8
              1985 1   .362963  .4206853  .3052406 .8
              1986 0  .3989362  .4394721  .3584002 .8
              1986 1  .4173913  .4815997  .3531829 .8
              1987 0   .361244  .4074832  .3150048 .8
              1987 1  .4810127  .5450866  .4169387 .8
              1988 0  .3624454  .4066352  .3182557 .8
              1988 1  .3722222  .4435193  .3009251 .8
              1989 0  .3126935    .36352   .261867 .8
              1989 1 .32402235   .393246 .25479868 .8
            1989.8 0        .3  .3521535  .2478465 .8
            1989.8 1  .3057851  .3890601 .22251016 .8
            1990.6 0  .2368421  .2924445 .18123972 .8
            1990.6 1  .3859649 .51628447 .25564533 .8
              1991 0  .2990937 .34867525 .24951206 .8
              1991 1  .4918033  .6209046 .36270195 .8
              1992 0  .3163539  .3637665 .26894125 .8
              1992 1 .53488374  .6902027  .3795647 .8
              1993 0 .22821577 .28158104  .1748505 .8
              1993 1  .5609756  .7195631  .4023882 .8
              1994 0  .3234324  .3764031 .27046162 .8
              1994 1  .3636364  .4827983  .2444744 .8
              1995 0  .3191489  .3791854  .2591125 .8
              1995 1       .25  .3985887 .10141131 .8
              1996 0 .20774648 .25521603 .16027693 .8
              1996 1  .3611111  .4747735 .24744873 .8
              1997 0  .2248062 .29781544 .15179695 .8
              1997 1  .3571429  .5463501  .1679356 .8
              1998 0 .17021276 .23300904 .10741649 .8
              1998 1  .3421053 .50013465 .18407585 .8
            end
            label values east east
            label def east 0 "West", modify
            label def east 1 "East", modify
            ------------------ copy up to and including the previous line ------------------

            Comment


            • #7
              Thanks, this will do. You need to place the line at the end of the code as Stata plots sequentially.

              Code:
              ||  scatteri 0.8 1984 0.8 2000, recast(line) lcolor(black)  lstyle(foreground) ;
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	91.5 KB
ID:	1613051

              Last edited by Andrew Musau; 03 Jun 2021, 17:39.

              Comment


              • #8
                Fantastic! Thanks so much, Andrew.

                Comment

                Working...
                X