Announcement

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

  • Twoway line panel graph title and second y

    I have been trying to add a general title and a second y variable title at right to a panel two-way line, but I am failing. I am using the following code

    Code:
    set scheme s1color
     
     twoway (line cpi ts if ts>0, yaxis(1)) (line u ts if ts>0, yaxis(2) lpattern(dash)) ,  title("Inflation consumer prices annual" "and Unemployment % of total labor force")  ytitle(Inflation consumer prices annual% ) ytitle((Unemployment % of total labor force), axis(2)) ttitle(year) legend(label(1 "consumer prices annual %")) legend(label(2 "Unemployment % of total labor force")) graphregion(color(white)) bgcolor(white)   title("Inflation consumer prices annual" "and Unemployment % of total labor force") by (id) ||

    and get the following messed up graph



    Click image for larger version

Name:	meessed.jpg
Views:	1
Size:	161.2 KB
ID:	1635474




    When I omit the title option in the above code

    Code:
     
     set scheme s1color
    twoway (line cpi ts if ts>0, yaxis(1)) (line u ts if ts>0, yaxis(2) lpattern(dash)) , ytitle(Inflation consumer prices annual% ) ytitle((Unemployment % of total labor force), axis(2)) ttitle(year) legend(label(1 "consumer prices annual %")) legend(label(2 "Unemployment % of total labor force")) graphregion(color(white)) bgcolor(white)   title("Inflation consumer prices annual" "and Unemployment % of total labor force") by (id)
    I get the graph below.



    Click image for larger version

Name:	forum.jpg
Views:	1
Size:	98.2 KB
ID:	1635473



    I would like to add a general title to the graph on the top as "Inflation, consumer prices annual and Unemployment % of total labor force" and a second y variable to appear to the right as "Unemployment % of total labor force", similarly to what appears the "Inflation consumer prices annual %" at left

    Where am I mistaking the code?

    Mario


  • #2
    The title option should be within the parenthesis of the by option:

    by(id, title("This is the general title"))

    Comment


    • #3
      Originally posted by alejoforero View Post
      The title option should be within the parenthesis of the by option:

      by(id, title("This is the general title"))
      Thank you very much alejoforero


      The code I run after your suggestion is

      Code:
       set scheme s1color  twoway (line cpi ts if ts>0, yaxis(1)) (line u ts if ts>0, yaxis(2) lpattern(dash)) ,  ytitle(Inflation consumer prices annual% ) ytitle((Unemployment % of total labor force), axis(2)) ttitle(year) legend(label(1 "consumer prices annual %")) legend(label(2 "Unemployment % of total labor force")) graphregion(color(white)) bgcolor(white)  by (id, title("Inflation, consumer prices annual and Unemployment % of total labor force"))
      and get an error
      Code:
         
      ) required
      r(100);

      I cannot see the missing parenthesis.



      Also, how can I include a title for the second y variable to appear to the right as "Unemployment % of total labor force", similar to what appears the "Inflation consumer prices annual %" at the left?
      Mario
      Last edited by Mario Ferri; 08 Nov 2021, 13:34.

      Comment


      • #4
        You cannot leave a space between the by and the parenthesis, that's causing the r(100) error.

        For the secondary yaxis title use the r2title option:
        Code:
         
         twoway (line cpi ts if ts>0, yaxis(1)) (line u ts if ts>0, yaxis(2) lpattern(dash)) ,  ytitle(Inflation consumer prices annual% ) ytitle((Unemployment % of total labor force), axis(2)) ttitle(year) legend(label(1 "consumer prices annual %")) legend(label(2 "Unemployment % of total labor force")) graphregion(color(white)) bgcolor(white)  by(id, r2title("Unemployment % of total labor force") title("Inflation, consumer prices annual and Unemployment % of total labor force"))

        Comment


        • #5
          Originally posted by alejoforero View Post
          You cannot leave a space between the by and the parenthesis, that's causing the r(100) error.

          For the secondary yaxis title use the r2title option:
          Code:
          twoway (line cpi ts if ts>0, yaxis(1)) (line u ts if ts>0, yaxis(2) lpattern(dash)) , ytitle(Inflation consumer prices annual% ) ytitle((Unemployment % of total labor force), axis(2)) ttitle(year) legend(label(1 "consumer prices annual %")) legend(label(2 "Unemployment % of total labor force")) graphregion(color(white)) bgcolor(white) by(id, r2title("Unemployment % of total labor force") title("Inflation, consumer prices annual and Unemployment % of total labor force"))
          Thank you very much. Your help has been precious. I am indebted to you!

          Comment

          Working...
          X