Announcement

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

  • Create observations that count

    Dear experts,

    I want to create a data set that has for variable i the numbers from 1 to 156 (counting basically), then for each variable i I want to create variable j that has 35 new observations (counting from 1 to 35) and last for each variable j I want 75 new observations (counting from 1 to 75).
    Put differently: I want to create variable Xijt that counts from i (1 to 156), from j (1 to 35), from t (1 to 75), so that I have only unique X combinations of these variables. e.g. X111, X112, X113, ... , X121, X122, ... , X156 35 75

    I tried with the following code, but it does not work... how can I achieve this?
    Code:
    set obs 409500
    egen i = seq(), f(1) t(156) b(2625)
    egen j = seq(), f(1) t(35) b(11700)
    egen t = seq(), f(1) t(75)  b(5460)
    Thanks in advance!



  • #2
    The following does what I think you want:
    Code:
    clear
    set obs 156
    gen int i = _n
    expand 35
    bysort i: gen int j = _n
    expand 75
    bysort i j: gen int t = _n

    Comment


    • #3
      Originally posted by Mike Lacy View Post
      The following does what I think you want:
      Code:
      clear
      set obs 156
      gen int i = _n
      expand 35
      bysort i: gen int j = _n
      expand 75
      bysort i j: gen int t = _n
      Thank you! That actually helped creating my matrix.

      I have the following regression equation:
      Yijt = alpha + beta * Xit-1 + gamma * Yijt-1 + delta * fixed effectsijt

      i is company, j is industry and t is quarter.

      I have an unbalanced data set. How can I set up a new panel data structure that fills missing observations with zeros. With my earlier question, I tried to set up the matrix manually and my next step would be to try insert my existing data into this matrix. Is there an easy way to do this?

      My dataex.
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double Yijt float(Yijt-1 Xit-1)
                     150     0     0
      290     0     0
                     220     0     100
                     150     0     0
                    87.5     0     0
                     255     0     -300
                     115     0     0
                     400     0     0
                     175     0     0
                     175     0     0
                    21.7     0     0
                   110.6     0     0
                      94     0     0
                      60     0     0
                      20     0     0
                      30     0     0
                    71.6     0     0
                      84     0     0
                     135     0     0
                      32     0     0
                      10     0     0
                     410     0     0
                    27.5     0     250
                      24     0     0
                      39     0     0
                      75     0     0
                      28     0     0
                      31     0     0
                     535     0     0
                    16.5     0     0
                     180     0     0
                     145   180     0
                    48.5     0     0
                      35     0     0
                     696     0     0
                     340     0     0
                      32     0     0
                     645     0     100
                      80     0     0
                      35     0     100
                     400     0     0
                      30     0     0
                     135     0     0
                      35     0     0
                     350     0     0
                     550     0     0
                     250     0     0
                     525     0     0
                   540.4   525     0
                     490     0     0
                     225     0     0
                     140     0     0
                     150     0     0
                     115     0     0
                     290     0     0
                   109.5     0     0
                     160     0     0
                    2600     0     0
                     200  2600     0
                    2760     0     0
                     200     0     0
                     425     0     0
                     330     0   -50
                     325     0     0
                     370     0 -1955
                      50     0   575
                      60     0     0
                     300     0     0
                     415     0     -300
                     715     0     0
                     125     0     0
                     375   125     0
                     536     0     0
                     300   536  -525
                     420     0     0
                     530     0     0
                     720     0     0
                     110     0     0
                   554.5     0     0
                    1075     0     0
                   533.7  1075     0
                     175 533.7     0
                     475   175     0
                     576     0     0
                     657     0     0
                     470     0     0
                     100     0     0
                     125     0     0
                     255     0     0
                     150     0     0
                     200     0     -300
                    1500     0     0
                     157     0     -300
                      50     0     0
                     365     0     0
                     330     0     0
                     565   330     0
                     400     0     0
                     425     0     0
                     775     0     0
      end

      Thanks in advance!

      Comment

      Working...
      X