Announcement

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

  • Why does Stata add a year that I don't need for my figure?


    I want to make a twoway connected graph on Stata. But even though there is no year 2022 in my dataset, it automatically adds the year 2022.

    Here, the code:

    twoway (connected usasecurity Year) (connected usaeconomic Year) (connected usadevhum Year)
    or
    twoway (connected usasecurity Year) (connected usaeconomic Year) (connected usadevhum Year) if Year<2022

    Even if I do it by using a conditional (Year<2022), it still gives me the graph with 2022. How can I solve this problem.

    Thank you so much, Best,

  • #2
    Stata's graph routines try to produce axis labels that include the full range of the data and also "look nice." It has its own algorithms for what "looks nice" and sometimes these result in labelings that are, for other reasons, not optimal. Perhaps your graph is being labeled with all even numbered years, and the last year in your data is 2021. Then Stata will add 2022 to the axis to preserve the pattern of even numbers and the inclusion of all of the data within the labeled part of the axis.

    If this is unsatisfactory for your purposes (or you just don't like it!) there is the -xlabel()- option in -twoway- which allows you to specify the labeling yourself. See -help axis_label_options- for details.

    Comment


    • #3
      Thank you Clyde,

      I will solve by labeling.

      Best

      Comment

      Working...
      X