Announcement

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

  • Twoway line

    I am analysing data for foursurvey years of the same survey that runs biannually (except the first two years) that I've merged as a single dataset

    When I run a twoway line chart, Stata 18 is filling in the "missing" years (which are not missing, just don't exist).

    Year variable is SurveyYear; 1==2018 2==2019 3==2021 4==2023

    I want the mean of the variable Superv_scale as the y variable over the four years:

    bysort SurveyYear: egen MeanSupvision = mean(Superv_scale)

    twoway line MeanSupvision SurveyYear

    The resulting graph shows each year from 2018 -2023 on the x axis.

    I saw a comment n the forum to add cmissing to the twoway line, but that didn't do anything noticeable.

    Any thoughts how to stop the filling in of years?


  • #2
    Perhaps you want just an extra option

    Code:
    xla(2019 2019 2021 2023)
    -- but I am not really clear what "filling in" means here.

    Comment


    • #3
      Thanks Nick, that works. By"filling in", I meant showing a each year 2018-2023 as equal scale intervals on the x axis, where as Surveyyear is not coded that way. Thinking about it, I have it as int datatype, so perhaps it makes sense for stata to interpret it that way

      Comment


      • #4
        You could always do this

        Code:
        egen Year = group(SurveyYear), label
        and then plot in terms of
        Code:
        Year
        .

        Code:
        twoway line MeanSupvision Year, xla(1/4, valuelabel)
        Choose between the folks on one side going "But that implies that your years are equally spaced, which they aren't" and the folks on the other side reacting to your previous graph "Why the unequal spacing? It's not helpful".

        I would go for what you had first. It's honest about the variable spacing and people can discount that easily enough if they wish,

        Comment


        • #5
          Thanks Nick, yes, exactly that. I am inclined to show the years as uneven, even if jarring to the eye. At least that jarring-ness draws attention to something important going on that could easily be overlooked on a slide.

          Comment

          Working...
          X