Announcement

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

  • Invalid Syntax when running this code

    Hello,

    I keep running into an error when I attempt to generate this graph. I am new to Stata, can anyone help me please. I have attached the code below:

    twoway (tsline dunemp_JPN if year>=2016), lw(.6)) ///
    (rarea lowf1 highf1 year if year>=2016), lcolor(white) fcolor(pink%30) lpattern(solid) lw(.2)) ///
    , scheme(s2mono) graphregion(color(white)) ///
    ysize(4) xsize(9) ylabel(, grid glc(black) glw(.2) glp(shortdash)) legend(off)

    Thanks,
    Milind

  • #2
    My prejudice here is that the () syntax for different twoway command calls is too easy to get wrong, as there are all too many parentheses otherwise. Try

    Code:
    twoway tsline dunemp_JPN if year>=2016, lw(.6) ///
    || rarea lowf1 highf1 year if year>=2016, lcolor(white) fcolor(pink%30) lpattern(solid) lw(.2) ///
    scheme(s2mono) graphregion(color(white)) ///
    ysize(4) xsize(9) ylabel(, grid glc(black) glw(.2) glp(shortdash)) legend(off)

    Comment


    • #3
      Thank you so much again Nick.
      The graph runs without error yet I just had another question relating to how to specify the axis range.
      I'm trying to specify the range of the axis from 2016 to 2019 yet when I run the graph, it seems to run from 2016 to 2464 which is way out of my data range lol.
      Is there a way I can specify the x-axis to only portray data from 2016 to 2019?

      Comment


      • #4
        Stata thinks that you have year values as high as 2464.

        The best way forward is not to mess with the graph command, but to see what the problem is, as incorrect values could mess up almost anything hence forward. One or more of

        Code:
        edit if year > 2024 
        
        list if year > 2024 
        
        tab year
        could help in tracking down the problem.


        Comment


        • #5
          I just ran the command and it seems that the data set does conclude at 2019 yet I wonder why STATA believes there are values that high.
          If I run this command without all the additional plot options then the x-axis does conclude at 2019.
          twoway line f1 year if year>=2016
          Could there potentially be an issue with the plot options that generate this error?

          Comment


          • #6
            Despite what you say I would bet that the problem is, or more precisely was, with your data and your code somehow.

            If there were a bug that bizarre in code, it would have bitten other users long since, and been fixed.

            It's quite common for example that junk that makes sense to a user of MS Excel as some extra stuff gets read into Stata as the value of a variable.

            Comment


            • #7
              I've just managed to sort it out, decided to overlay the shaded area on top of the initial line. I appreciate you help you have provided me.

              Comment

              Working...
              X