Announcement

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

  • Dataex- date ranges

    I have read the dataex manual but I am still a bit confused about how to present data in the range of dates I want it. Would I be able to have some help with this?

  • #2
    There aren't any special instructions here because they aren't needed: you can just use an if qualifier to select, Here are some examples.

    I tend to use inrange() because I am familiar with it but other way round people might reasonably (more reasonably!) reach for tin().

    Perhaps an example of this kind should be added to the help. StataCorp are a bit coy about this command being community-contributed but just happening to be distributed with Stata, but my view is that it was given to the company and the community by the authors for general use.

    Code:
    . webuse grunfeld, clear
    
    . dataex if inrange(year, 1939, 1940)

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte company int year float(invest mvalue kstock) byte time
     1 1939 330.8 4313.2 203.4 5
     1 1940 461.2 4643.9 207.2 6
     2 1939 230.4 1957.3 312.7 5
     2 1940 361.6 2202.9 254.2 6
     3 1939  48.1 2256.2 172.6 5
     3 1940  74.4 2132.2 186.6 6
     4 1939 52.41  679.7  64.3 5
     4 1940 69.41  727.8  67.1 6
     5 1939 42.65  191.4 323.1 5
     5 1940 46.48  185.5   344 6
     6 1939  24.6  286.4  48.6 5
     6 1940 28.54    298  52.5 6
     7 1939 26.65  161.7 194.8 5
     7 1940 33.71  145.1 222.9 6
     8 1939 18.84  519.9  23.5 5
     8 1940 28.57  628.5  26.5 6
     9 1939 28.78  356.2   208 5
     9 1940 26.93  289.8   223 6
    10 1939  2.03  80.54  4.38 5
    10 1940  1.81  86.47  4.21 6
    end
    format %ty year

    Code:
    . clear
    
    . set obs 730
    Number of observations (_N) was 0, now 730.
    
    . gen ddate = mdy(12, 31, 2021) + _n
    
    . format ddate %td
    
    . dataex if inrange(ddate, mdy(1,1,2022), mdy(1,31,2022))

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float ddate
    22646
    22647
    22648
    22649
    22650
    22651
    22652
    22653
    22654
    22655
    22656
    22657
    22658
    22659
    22660
    22661
    22662
    22663
    22664
    22665
    22666
    22667
    22668
    22669
    22670
    22671
    22672
    22673
    22674
    22675
    22676
    end
    format %td ddate
    Last edited by Nick Cox; 01 Feb 2023, 04:58.

    Comment


    • #3
      Thank you Nick, that was super helpful!

      Comment

      Working...
      X