Announcement

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

  • Changing the label of a graph

    Hello all, I am fairly new to stata. I have this graph and I am desperately trying to get the x-axis to stop at 2016 (the last year of observations). I tried many different things. The code for the graph I'm currently using is:

    graph twoway line var1 year, lc(black) lpattern(dash) legend(label(1 "X")) || line var2 year, lc(red) lpattern(dash) legend(label(2 "Y")) title("title") note("description") ylabel(,angle(horizontal)) xscale(range(1980 2016))

    Event though I use the xscale command, it doesnt do anything. I tried many different things, using the xtick command, changing the graph to a line and a xtline.. But I always get the same graph.
    Help would be much appreciated.
    Best
    L




    Click image for larger version

Name:	Screenshot 2023-03-22 103958.png
Views:	1
Size:	42.1 KB
ID:	1706553






  • #2
    Does the data go beyond 2016? If so, add an -if- restriction:

    Code:
    graph twoway line var1 year if year<=2016
    You can also try adding

    Code:
    xlab(1980(10)2010)
    Otherwise, a data example will help your case here. Refer to FAQ Advice #12.

    Comment


    • #3
      I agree broadly with Andrew Musau. The issue is that graph looks at the range of your x variable and decides that 1980(10)2020 would look good as axis labels.

      xscale() won't override that, but something like

      Code:
      xla(1984 1990(10)2010 2016) 
      as an extra option would probably do what you want. Here 1984 is just an eyeball guess at your first year. Or 1983?

      Comment

      Working...
      X