Announcement

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

  • Drop dates except for 1 specific month over 5 years

    Hi, I would like to only keep the data from may of each year in a dataset of every month from 2014-2018. So, I only want May 2014,2015,etc. What code/ drop should I use? Thanks!

  • #2
    Data example with dataex please. Welcome to Statalist!



    Without this.... the very very lazy way I would do this, assuming I had monthly data, would be
    Code:
    g keepdate = cond(month==5 & inrange(year,2014,2018),1,0)
    
    keep if keepdate
    Note that I'm not at my computer, so this is my code from the top of my head. For a better response, we'll need to see your data.


    Edit: and also, why? Why do you want this? I'm not saying it's bad, but why do you want such a specific time period? I'm curious.

    Other edit: this ain't Stack Overflow. To promote professionalism on Statalist, we require all members use their real names. You can, I think, contact sladmin for this, that is, if you plan to stick around for any period of time.
    Last edited by Jared Greathouse; 30 Apr 2023, 17:45.

    Comment


    • #3
      Hi, thank you, and sorry for not uploading the dataset. I am looking for annual financial ratios, but the dataset has only monthly. It was recommended to me to look at just Mays as the annual ratio. I do not know the exact reason. Also the data has like 200,000 columns. The data is financial ratios for all companies on the compustat database and I am not sure if I can post that dataset.

      Comment


      • #4
        Just type in dataex into your terminal and post exactly as it says

        Comment


        • #5
          The only detail of obvious importance is how your dataset is holding dates. So the dataex callneed only cover date-related variables.

          Comment

          Working...
          X