Announcement

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

  • Help with specifying a multi-line local

    Dear All,
    This should be straightforward, but I am really struggling with specifying a multiple line local that I want to use to add text to a twoway graph.

    Code:
    local textYTreatment `"3.15 -1 `""Text here," "here also" "and here""'"'
    
    
    foreach Y in  Y{
    foreach T in  Treatment{
            
        ppmlhdfe `Y' ws_`T'_1- ws_`T'_10 ws_`T'_12- ws_`T'_23 , ///
        absorb(state_d time, save) cluster(state_d)
        
        # delimit ;
        twoway
            (rarea upper_`Y'`T' lower_`Y'`T' timeG if inrange(timeG, -10,10), color(gs12%35)),
             xsize(3) ysize(2)
          text("`text`Y'`T''")
            name(`Y'`T', replace)
         ;
        # delimit cr
         graph export "$results\`Y'`T'.png",  replace  width(4000)    
     
    }
    }
    Unfortunately I get the following error message:

    Code:
    too few quotes
    r(132);
    I have tried adding and removing quotes but I seem to be doing something fundamentally wrong it seems. Any help would be much appreciated.
    Sincerely,
    Sumedha

  • #2
    Perhaps it might help to change the double quotes surrounding your text() argument
    Code:
    text("`text`Y'`T''")
    to compound double quotes
    Code:
    text("`text`Y'`T''")
    I know you have compound double quotes in your local command, but consider the following.
    Code:
    . local textYTreatment `"3.15 -1 `""Text here," "here also" "and here""'"'
    
    . macro list _textYTreatment
    _textYTreatment:
                    3.15 -1 `""Text here," "here also" "and here""'
    When defining a local or global macro, if Stata encounters a double quote (or compound double quote) as the first character, it will expect a matching double quote as the final character, and will remove both.

    I will admit I'm not convinced this will help, but it's worth trying.

    Comment


    • #3
      Thank you Prof. Lisowski. Sorry for being confused, but I don't see the difference between the line you suggested changing and the code you suggested changing it to (besides the red font):

      Code:
      text("`text`Y'`T''")
      to compound double quotes
      Code:
      text("`text`Y'`T''") Might you be able to explain please? Many thanks, Sumedha

      Comment


      • #4
        I am embarrassed. I think I was interrupted and lost my train of thought while I was posting. Here it is, corrected, with the before-and-after in red and in a larger point size to help me make sure I made the changes I intended to.

        Change
        Code:
        text("`text`Y'`T''")
        to
        Code:
        text(`"`text`Y'`T''"')
        After all that, I hope it helps.

        Comment


        • #5
          Thank you so much for responding so quickly and helping. I tried the change now, but still no luck. Though the error message now changed:

          Code:
          invalid point,  3.15 -1 `""Text here," "here also" "and here""'
          r(198);
          Any thoughts?
          Gratefully,
          Sumedha

          Comment


          • #6
            Aha. I think twoway is now interpreting (at least the first two of) the arguments to the text() option as they were meant to be interpreted, and is complaining that y=3.15 x=-1 is not within the ranges on your graph.

            Some experiments to try.

            1) Remove the text() option and see what the ranges shown on the axes of your graph are.

            2) If y=3.15 x=-1 seems to be within the ranges shown of your graph, return the text() option to your code but simplify textYTreatment to see if it works with a single line.
            Code:
            local textYTreatment `"3.15 -1 "Text here,""'
            3) If that works then try a slight variation on the original textYTreatment
            Code:
            local textYTreatment `"3.15 -1 "Text here," "here also" "and here""'
            which is more consistent with the documentation - multiple lines of text are not shown to be surrounded by compound quotes in the documentation.

            And if all else fails.
            ∞) Your time axis is timeG. Is that a variable with a time format, in which case perhaps you need ttext() and a date value.

            Comment


            • #7
              Thank you again for suggesting steps. I tried them. Y=3.15, x=-1 is in range. I tried it by removing the local and directly putting the text in twoway as follows:

              Code:
               
               foreach Y in  Y{ foreach T in  Treatment{              ppmlhdfe `Y' ws_`T'_1- ws_`T'_10 ws_`T'_12- ws_`T'_23 , ///     absorb(state_d time, save) cluster(state_d)          # delimit ;     twoway         (rarea upper_`Y'`T' lower_`Y'`T' timeG if inrange(timeG, -10,10), color(gs12%35)),          xsize(3) ysize(2)       text(3.5 -1 "Text here," "here also" "and here")         name(`Y'`T', replace)      ;     # delimit cr      graph export "$results\`Y'`T'.png",  replace  width(4000)       } }
              Here is the output:
              stataex.gph



              So, only the local doesn't seem to work...
              Sincerely,
              Sumedha

              Comment


              • #8
                maybe the following example code helps:
                Code:
                * A
                
                local text 1 1 "Text here," "here also" "and here"
                tw scatteri 1 1 , m(none) text(`text')
                
                * B
                
                local text \`y' \`x' "Text here," "here also" "and here"
                
                local y 1.5
                local x 1
                
                tw scatteri 1 1 , m(none) text(`text')
                
                * C
                
                local y 1
                local x 1.5
                
                local text `y' `x' "Text here," "here also" "and here"
                
                tw scatteri 1 1 , m(none) text(`text')
                Last edited by Bjarte Aagnes; 22 Jul 2022, 05:01.

                Comment


                • #9
                  Hi Bjarte,
                  Thank you so much for your guidance. Option C above worked perfectly for me!
                  Many thanks again,
                  Sumedha

                  Comment

                  Working...
                  X