Announcement

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

  • Vertical Line Label

    Hey,

    I am trying to put labels on vertical lines in a twoway line graph. I was first trying to use xlabel() for this purpose but could not figure out how to get the labels at the top of the line. I instead opted for the Text(xxx xxx "xx") command which worked satisfactorily.
    My problem now, I will attach a image below, is that the lines are too tight to fit the labels. My idea is to increase the blank space above the graph while keeping the lines the same length and maybe adding some "arrows" from the label to the line, (I think the labels might be too small to read if I just put them right above the vertical lines).

    I have used this command to execute the graph

    twoway (line so_innehav1 date1), xline(20131, lapattern(dash) lcolor(red) text(600000 20131 "QE1")

    I am new here and this is my first post so I am sorry if it is not perfectly organized.

    Click image for larger version

Name:	bild.png
Views:	1
Size:	166.0 KB
ID:	1573589

  • #2
    I would add labels on a second x axis.

    This shows some technique. In this case and yours,

    1. You surely don't need to show the variable name on the x axis, as it is evident enough what the axis shows,

    2. There is no obvious need to repeat "QE". As someone British I think "Queen Elizabeth" but I doubt that fits your case. You can put good text in an axis title at the top.

    For your case, see also https://www.stata-journal.com/articl...article=gr0030


    Code:
    . webuse grunfeld , clear
    
    . set scheme s1color 
    
    . line invest year if company == 1 , xaxis(1 2) xla(1939 "1" 1941 "2" , axis(2)) xtitle("", axis(2)) xtitle("")
    Click image for larger version

Name:	extralabels.png
Views:	1
Size:	21.7 KB
ID:	1573613

    Comment


    • #3
      Hello, and thank you for your answer.

      I struggled a bit to get everything right but I think I have managed alright now. Maybe it is easier to guess what QE stands for now as well...

      One thing I could not find an answer on is related to the article. I used the following code:

      Code:
      xlabel(19540(365)22097)
      xtick(19359 19724 20089 20454 20820 2118521550 21915, noticks format(%tdCY)) xtitle("")
      Which worked alright, but I noticed that it gets wrong when there is a leap year, which is why I wrote out every date on the xtick part of the code.

      Is there a way around that?

      Click image for larger version

Name:	bilh.png
Views:	1
Size:	160.3 KB
ID:	1573638


      /Nils

      Comment


      • #4
        Leap years or not, it suffices to have a label for every 1 January.


        Code:
         local wanted
        
        forval y = 2013/2020 {
             local wanted `wanted' `=mdy(1,1,`y')'
        }
        
        di "`wanted'"
        
        19359 19724 20089 20454 20820 21185 21550 21915

        Comment

        Working...
        X