Announcement

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

  • Different y-axis range on xtline plots

    I'm trying to construct some xtline plots using 10 different ids. The range of values of y for id #s 1-9 is 0-100, but for id #10 the range of values for y is 0-2000. This causes xtline to set the y axis range from 0 to 2000, making the plots for id #s 1-9 effectively meaningless because the y axis' range is so large compared to the actual range of values.

    Is there a way to alter the y axis on individual xtline plots? The only solutions I've found so far is to simply exclude the problematic id using an if condition or to manually create individual graphs for each id using twoway line, but I'm sure there's a better way to deal with this issue.

    If it helps, here's a sample dataset and two graphs to illustrate the problem:

    Code:
    clear
    set obs 10
    gen id = _n
    expand 20
    bys id: egen time = seq(),f(1) t(20)
    xtset id time
    gen var1 = runiformint(0,100) if id !=10
    replace var1 = runiformint(0,2000) if id == 10
    xtline var1
    xtline var1 if id !=10
    Any help is much appreciated.
    Click image for larger version

Name:	image_20852.png
Views:	1
Size:	79.5 KB
ID:	1587785 Click image for larger version

Name:	image_20853.png
Views:	1
Size:	141.4 KB
ID:	1587786
    Last edited by Ali Atia; 30 Dec 2020, 05:36.

  • #2
    Code:
    clear
    set obs 10
    gen id = _n
    expand 20
    bys id: egen time = seq(),f(1) t(20)
    xtset id time
    gen var1 = runiformint(0, cond(id == 10, 2000, 100)) 
    
    line var1 time, by(id, yrescale note(""))

    Comment


    • #3
      Perfect, thank you!

      Comment

      Working...
      X