Announcement

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

  • xlabel does not work for restricting the x-axis

    Hi,

    I am plotting the mean of treatment and control groups. My data period (and naturally, my x-axis) is long so I would like to focus on the middle section of my graph and for this end, I use xlabel but it does not work.

    I am working with quarterly data (qdate: 2016q3 etc.). I already formatted this date successfully via %tq and set my main time variable with xtset. I run the following code:

    Code:
    scatter std_mean_y1  qdate, connect(l) sort || scatter std_mean_y0 qdate, sort connect(l) xlabel(215(1)225)
    This does not work. It only puts the labels in the x-axis but it does not restrict the axis.

    Start date: 2011q3 (x-axis value: 206)
    End date: 2019q4 (x-axis value: 239)

    My bonus question is to how to plot a fitting line for each of the variables before and after a cutoff date (pre and post intervention periods). How can I accomplish it with lfit?

  • #2
    It [xlabel()] only puts the labels in the x-axis but it does not restrict the axis.
    This is a commonly encountered difficulty. I'm not sure why, since the help and PDF documentation state very clearly that this is exactly what -xlabel()- does:
    ylabel(rule_or_values), xlabel(rule_or_values), tlabel(rule_or_values), and
    zlabel(rule_or_values) specify the major values to be labeled and ticked along the
    axis.
    For instance, to label the values 0, 5, 10, ..., 25 along the x axis, specify
    xlabel(0(5)25). If the t axis has the %tm format, tlabel(1999m1(1)1999m12) will
    label all the months in 1999.
    It say nothing at all about defining the extent of the axis. To restrict an axis, you have to add an -if- qualifier to the graph command. So what you want is:
    Code:
    scatter std_mean_y1 qdate if inrange(qdate, 215, 225), connect(l) sort || scatter std_mean_y0 qdate if inrange(qdate(215, 225), sort connect(l) xlabel(215(1)225)
    The same will apply to -lfit-: use an -if- clause to restrict the range of qdate.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      This is a commonly encountered difficulty. I'm not sure why, since the help and PDF documentation state very clearly that this is exactly what -xlabel()- does:

      It say nothing at all about defining the extent of the axis. To restrict an axis, you have to add an -if- qualifier to the graph command. So what you want is:
      Code:
      scatter std_mean_y1 qdate if inrange(qdate, 215, 225), connect(l) sort || scatter std_mean_y0 qdate if inrange(qdate(215, 225), sort connect(l) xlabel(215(1)225)
      The same will apply to -lfit-: use an -if- clause to restrict the range of qdate.
      Many thanks Clyde! I am now able to obtain the graph. However, I am still having troubles in putting linefits for each variable before and after a cutoff date (for instance; 220)

      Comment


      • #4
        As there is no example data to work with, this code is untested and may not work, but it should point you in the right direction.

        Code:
        lfit std_mean_y1 qdate if inrange(qdate, 215, 220) || lfit std_mean_y1 qdate if inrange(qdate, 220, 225)

        Comment

        Working...
        X