Announcement

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

  • Using tin() for xrange specification

    I am trying to create twoway scatters with panel data that I have, but there are many different variables and a few of them don't have any data until later on in the time sequence. However, when I just do a regular twoway scatter, it still starts my x axis at the first month in the entire panel data, but there isn't any data for another few months after that, so there's a big gap at the start of the scatterplot.

    I started with this code, trying to use tin() which I thought may solve my problem, but only gives me a syntax error:


    Code:
    twoway scatter employee_points date1 if tin(11/1/17, 6/1/18), graphregion(color(white)) msize(small) ///
    ytitle(Employee Points Per Capita) xtitle(Date) title(Employee Points) ///
    legend(off) || lfit employee_points date1, lcolor(orange)
    I'm guessing the issue is either with my syntax or the way my date is formatted (or maybe both). Here is a sample of my data:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str5 office_name double(employee_points employee_bonus) int(tech_avg date1)
    "Mill"          .  6.776062 143 20759
    "Mill"          . 6.7323942 106 20789
    "Mill"          . 7.1149998 137 20820
    "Mill"          . 5.6445313 111 20851
    "Mill"          . 5.8468084 113 20879
    "Mill"          .  4.855814 126 20910
    "Mill"          . 5.5550461 109 20940
    "Mill"          . 4.8366337 107 20971
    "Mill"          . 5.1826482 126 21001
    "Mill"          . 4.9078946 113 21032
    "Mill"          . 5.7422223 117 21063
    "Mill"          . 4.6510639 118 21093
    "Mill"  353.48761 5.9055796  96 21124
    "Mill"  384.31689 7.0921054  89 21154
    "Mill"  373.18961 6.4054055 100 21185
    "Mill"  192.74236 3.7630057  84 21216
    "Mill"  258.95181 4.5294118 101 21244
    "Mill"  135.85597 4.3128834  94 21275
    "Straw"  349.7821 6.5738831  39 21124
    "Straw" 409.04315 6.3429751  19 21154
    "Straw" 352.25089 5.7017546  34 21185
    "Straw" 324.26953 6.4699998  23 21216
    "Straw" 373.58566 5.9000001  35 21244
    "Straw" 291.13821 5.3299494  22 21275
    "Straw" 244.25714 4.8553457  24 21305
    "Weber"         . 3.3506494 175 20759
    "Weber"         . 4.6906476 105 20789
    "Weber"         . 3.6909091 145 20820
    "Weber"         . 2.9133334 134 20851
    "Weber"         .  2.789855 147 20879
    "Weber"         . 2.3785715 144 20910
    "Weber"         . 2.5342467 133 20940
    "Weber"         . 1.9722222 153 20971
    "Weber"         . 2.3252032 115 21001
    "Weber"         . 1.6049383 103 21032
    "Weber"         . 2.1323528  77 21063
    "Weber"         .  2.108108 119 21093
    "Weber" 90.023811     1.875  71 21124
    "Weber" 83.993507 2.6129031 110 21154
    "Weber" 121.29341 2.5932202  92 21185
    "Weber" 125.11539 2.9908257  90 21216
    "Weber" 115.19892 2.4285715 101 21244
    "Weber" 92.515724 2.4684684  70 21275
    "Weber"  111.6625 2.7479675 100 21305
    "Weber" 118.72186 2.6774194  93 21336
    end
    format %tdnn/dd/CCYY date1
    Last edited by Taylor Walter; 15 Aug 2018, 12:22.

  • #2
    See

    Code:
    help tin()
    I guess you need either

    Code:
    tin(11jan2017, 6jan2018)
    or

    Code:
      
    tin(1nov2017, 1jun2018)
    depending on what you mean. Stata doesn't know your personal preferences or conventions, so needs unambiguous details.

    Comment


    • #3
      Yes, I figured out that I did my -tsset- differently than I remembered. I had it in %tm format, so the correct code would be:

      Code:
      if tin(2017m11, 2018m6)
      Thanks much, Nick.

      Comment


      • #4
        It's not clear to me that will work without pushing your daily dates through mofd().

        Comment


        • #5
          I already did this earlier:

          Code:
          gen date1 = mofd(date)
          format date1 %tm

          I have a second unrelated question that has come up: with my new graph, the dates along the tick marks of the x axis are too big and the final one gets cut off on the right size. I can't seem to figure out what will alter the size of that font.

          Comment


          • #6
            OK, I hope, but that's not consistent with #1. date1 is clearly a daily date variable in #1. You can do what you like but we can only understand a full and consistent story.

            On dates being too big: there are many solutions. One is to use a different format. For dates like those in 2016 and 2017 sometimes the "20" is dispensable. Alternatively, add a little space on the right hand side with xsc() or yet again hand-engineering the last label by adding spaces at the right and so pushing what you see a little to the left.

            Comment


            • #7
              It seems like the only option I can (easily) get to work is using the data editor under "label properties" and changing size to "small"...the ticks and spaces wouldn't do it. What is the syntax for changing that size? I don't like to rely on the data editor if possible.

              Comment


              • #8
                Code:
                help axis label options
                
                sysuse auto, clear
                scatter mpg weight, xla(, labsize(small))

                Comment

                Working...
                X