Announcement

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

  • Generate a time variable

    Hi everybody,


    I have monthly data and I want to transform it to quarterly data.
    I transform my oberservations so that they are quarterly but for all three months per quarter. So I have to delete the first two months of each quarter.

    My idea was to compute a time variable for each third, sixth, nineth und twelveth month and delete all other observations.

    So, how can I generate such a time variable?


    With kind regards
    Bene Eil

  • #2
    Let's work this out with a sandbox.

    Code:
    clear
    set obs 12
    gen mdate = ym(2015, _n)
    gen minq = mod(mdate, 3)
    format mdate %tm
    l, sep(0)
    
         +----------------+
         |   mdate   minq |
         |----------------|
      1. |  2015m1      0 |
      2. |  2015m2      1 |
      3. |  2015m3      2 |
      4. |  2015m4      0 |
      5. |  2015m5      1 |
      6. |  2015m6      2 |
      7. |  2015m7      0 |
      8. |  2015m8      1 |
      9. |  2015m9      2 |
     10. | 2015m10      0 |
     11. | 2015m11      1 |
     12. | 2015m12      2 |
         +----------------+
    Clearly the same pattern is going to repeat in every year.

    So, one handle is that if you have monthly dates mdate, it is true that mod(mdate, 3) is 2 if and only if it's the end of a quarter. That is raw material for an if condition. Otherwise consult the help on dates to find that conversion of months to quarters is a nested function call qofd(dofm()).

    Comment


    • #3
      Generate year variable
      Hi everyone
      i have panel data of 106 countries for 2007-2020, and i want to generate year variable for 2007-2020.
      pls what is the code?
      Thanks

      Comment


      • #4
        How do you know that you have data from 2007-2020 if you do not have a year variable? It would be helpful to provide a data example, e.g., by copying and pasting the result of

        Code:
        dataex in 1/20

        Comment


        • #5
          i mean year dummy variable

          Comment


          • #6
            In addition, what is the stata code for estimating descriptive statistic by quantile. i want nq(4).
            Thanks

            Comment


            • #7
              Please give your example data using the dataex command. For us to provide meaningful feedback, you must provide either: your example data using the dataex command, the real data from an easily importable source (i.e., Github), or the equivalent of a toy example.
              Otherwise, anything we say is simply a waste of time. Note, that I'm not trying to be mean in saying this, I'm saying this because if we can't see your dataset exactly as you do with a minimal worked example, anything we suggest is just guesswork. Questions like this one likely have a relatively simple fix, but even simple fixes can be wildly overcomplicated without a minimal worked example of a dataset and code that you've tried to accomplish your task.

              So please, provide us with your example data that encapsulates the problem and we're more than okay with helping you solve this.

              Comment

              Working...
              X