Announcement

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

  • Legend placement for xtline var1 var2, legend(position(6)) does not work

    I am trying to place my legend at the bottom of my graph when I am plotting two variables in my xtset data. Using help legend, I have read on the position(clockposstyle), but I can not get the legend to show up at position(6). Instead it always stays at position(3). MRE:

    Code:
    * Clearing existing data and setting up
    clear
    set obs 64
    
    * Creating the panel identifiers
    gen country_id = ceil(_n/4)
    gen year = 2001 + mod(_n-1, 4) + 1  
    
    * Labelling countries for readability
    label define country_label 1 "Country01" 2 "Country02" 3 "Country03" 4 "Country04" 5 "Country05" 6 "Country06" 7 "Country07" 8 "Country08" 9 "Country09" 10 "Country10" 11 "Country11" 12 "Country12" 13 "Country13" 14 "Country14" 15 "Country15" 16 "Country16"
    label values country_id country_label  
    
    * Setting up the panel data structure
    xtset country_id year  
    
    * Generating random variables x and y
    set seed 0
    gen x = rnormal()
    gen y = rnormal()  
    
    * Display the first 20 observations
    list country_id year x y in 1/20, sepby(country_id)  
    
    xtline x y, legend(position(6))
    Crossposted from StackOverflow.
    Last edited by Felix Kaysers; 17 Dec 2023, 07:09. Reason: Fixed formatting
    Cheers,
    Felix
    Stata Version: MP 18.0
    OS: Windows 11

  • #2
    Code:
    xtline x y, byopts(legend(position(6)))

    Comment


    • #3
      Thank you! Of course, it had to be that easy.
      Cheers,
      Felix
      Stata Version: MP 18.0
      OS: Windows 11

      Comment

      Working...
      X