Announcement

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

  • What is the problem in my code on graphing?

    gr tw (scatter pgratioregional year, by(region)) (lfit pgratioregional year, by(region)) ///
    xlabel(1996(1)2006, angle(45)) xline(2001, style(dashed)) ///
    xtitle("", margin(medsmall) size(medlarge)) ///
    ytitle("Spending", margin(medsmall) size(medlarge)) scheme(s1mono) ///
    legend(off) note ("Note: The vertical dashed line marks 2001.", size(tiny))

    By running the above, I got ") required" r(100) error.

    Thanks!

  • #2
    Luckily no data are needed here. Your parentheses aren't balanced... Apparently. Honestly, in situations like this, I remove each option one by one until it runs correctly, and whatever I last removed, that has to be the option where the problem was.


    Not the most eloquent way. But perhaps someone else may know better?

    Comment


    • #3
      I think you need a comma,
      Code:
      gr tw (scatter pgratioregional year, by(region)) (lfit pgratioregional year, by(region)), ///
      xlabel(1996(1)2006, angle(45)) xline(2001, style(dashed)) ///
      xtitle("", margin(medsmall) size(medlarge)) ///
      ytitle("Spending", margin(medsmall) size(medlarge)) scheme(s1mono) ///
      legend(off) note ("Note: The vertical dashed line marks 2001.", size(tiny))

      Comment


      • #4
        Note that without a data example we can't run this code. Beyond that, I have three comments.

        1. I prefer the || notation for combining twoway commands if only because even without it there are very often already several parentheses to watch.

        2. The space after note may be a problem.

        3. Stata's do-file editor shows you the match for any parenthesis, and the same functionality is part of any decent text editor.

        Try this instead

        Code:
        scatter pgratioregional year, by(region) ///
        || lfit pgratioregional year, by(region) ///
        xlabel(1996(1)2006, angle(45)) xline(2001, style(dashed)) ///
        xtitle("", margin(medsmall) size(medlarge)) ///
        ytitle("Spending", margin(medsmall) size(medlarge)) scheme(s1mono) ///
        legend(off) note("Note: The vertical dashed line marks 2001.", size(tiny))

        Comment


        • #5
          Thank you all very much!

          Nick Cox I tried Mr. Cox's code, but legend is still there and there is the same note under all six graphs (six regions) . I don't want the legend and just need one note under all six graphs. How to get this? Many thanks!

          Comment


          • #6
            So, now you have a different question which is that you don't want what you asked Stata to give you.

            Again, there is no data example from you to let us see what is going on.

            However, tucking options inside by() may be the fix you need.

            Code:
              
            scatter pgratioregional year, by(region, legend(off) note("Note: The vertical dashed line marks 2001.", size(tiny))) ///
            || lfit pgratioregional year, ///
            xlabel(1996(1)2006, angle(45)) xline(2001, style(dashed)) ///
            xtitle("", margin(medsmall) size(medlarge)) ///
            ytitle("Spending", margin(medsmall) size(medlarge)) scheme(s1mono)
            PS: There is no need to call me Mr. People guessing at titles often get them wrong, any way. Just use my name, please, as indicated.

            Comment


            • #7
              It seems that I was not clear enough in the previous post. Mr. Cox's code works well, many thanks. But I want the legend off (it is still there) and only one note under all six graphs (instead of each note under each of the six graphs).

              Comment


              • #8
                It works well. It makes such difference in put the legend and off in different places! Thank you very much, Nick! I got all your points

                Comment

                Working...
                X