Announcement

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

  • Creating a panel data example

    Dear Stata users,

    I want to create a fake panel data example. I wanna have quarterly data for my id's.

    I tried the code:
    Code:
    set obs 100
    gen id=seq(), block(20)
    gen t=seq(227), to(247)
    I have an error when creating t: r(101) varlist not allowed

    I want to have quarterly data from (2016,4) for every id

  • #2
    Guest,

    you may want to try:
    Code:
    . set obs 100
    Number of observations (_N) was 0, now 100.
    
    
    . egen id=seq(), block(20)
    
    
    . egen t=seq(), to(247)
    
    .
    Last edited by sladmin; 28 Aug 2023, 08:34. Reason: anonymize original poster
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you Carlo for your answer. It isn't exactly what I want because time is not repeating. I wanna have for the different id's the same time, e.g. id 1 2016 quarter 4 and then again id 2 2016 q4. On the other hand time is starting from 1. I would like it would start from 2016 quarter 4

      Comment


      • #4
        Code:
        set obs 100
        egen id=seq(), block(20)
        bys id: g time=tq(2016q3)+_n
        format time %tq
        Res.:

        Code:
        . l if time<tq(2018q1), sepby(id)
        
             +-------------+
             | id     time |
             |-------------|
          1. |  1   2016q4 |
          2. |  1   2017q1 |
          3. |  1   2017q2 |
          4. |  1   2017q3 |
          5. |  1   2017q4 |
             |-------------|
         21. |  2   2016q4 |
         22. |  2   2017q1 |
         23. |  2   2017q2 |
         24. |  2   2017q3 |
         25. |  2   2017q4 |
             |-------------|
         41. |  3   2016q4 |
         42. |  3   2017q1 |
         43. |  3   2017q2 |
         44. |  3   2017q3 |
         45. |  3   2017q4 |
             |-------------|
         61. |  4   2016q4 |
         62. |  4   2017q1 |
         63. |  4   2017q2 |
         64. |  4   2017q3 |
         65. |  4   2017q4 |
             |-------------|
         81. |  5   2016q4 |
         82. |  5   2017q1 |
         83. |  5   2017q2 |
         84. |  5   2017q3 |
         85. |  5   2017q4 |
             +-------------+
        
        .

        Comment


        • #5
          Thank you so much Andrew for your kind help!

          Comment

          Working...
          X