Announcement

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

  • Need help on histogram range

    I hope everything to work out well in your lives.

    Here's the question: How can I draw histograms for each year around specific periods?

    Data looks like:

    FirmNo. Yr FDate PDate
    002410 2010 20100120 20100221
    002410 2011 20110121 20110222
    002410 2012 20120124 20120222
    002319 2010 20100127 20100219
    002319 2011 20110124 20110220
    002319 2012 20120119 20120222

    When I make histogram, it shows whole period on x axis, so it is impossible for me to look at frequency of the dates (FDate and PDate each) that the firms make announcements.

    I want the histogram each year to show certain periods only. (e.g. 20100101 ~ 20100228)

    Thank you in advance, and please let me know if I have to give more information.

  • #2
    It's hard to comment on your histogram (we can't see it) or your histogram command (you don't show that either).

    What can be guessed is that your daily dates are not fit for most purposes. See


    Code:
    help datetime

    for guidance. Here is some technique


    Code:
    clear
    input str6 FirmNo Yr long(FDate PDate)
    002410 2010 20100120 20100221
    002410 2011 20110121 20110222
    002410 2012 20120124 20120222
    002319 2010 20100127 20100219
    002319 2011 20110124 20110220
    002319 2012 20120119 20120222
    end
    
    gen GoodPDate = daily(string(PDate, "%8.0f"), "YMD")
    
    format GoodPDate %td
    
    list, sep(0)
    
         +-------------------------------------------------+
         | FirmNo     Yr      FDate      PDate   GoodPDate |
         |-------------------------------------------------|
      1. | 002410   2010   20100120   20100221   21feb2010 |
      2. | 002410   2011   20110121   20110222   22feb2011 |
      3. | 002410   2012   20120124   20120222   22feb2012 |
      4. | 002319   2010   20100127   20100219   19feb2010 |
      5. | 002319   2011   20110124   20110220   20feb2011 |
      6. | 002319   2012   20120119   20120222   22feb2012 |
         +-------------------------------------------------+
    Perhaps

    Code:
    ... if inrange(GoodPDate, mdy(1,1,2010), mdy(2, 28, 2010))
    is the qualifier you are looking for. In fact,

    Code:
    .. if inrange(PDate, 20100101, 20100228)
    should also work, but don't be misled into thinking that such dates are good for most Stata purposes.

    Last edited by Nick Cox; 16 Oct 2019, 00:36.

    Comment


    • #3
      Thank you so much!

      But what type of date is more of Stata purpose? I have very little knowledge about the software... please understand.

      Comment


      • #4
        I understand. That is why I advised you generally to read

        Code:
        help datetime
        and showed you specifically how to get Stata date variables out of your data.

        Comment

        Working...
        X