Announcement

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

  • Create a matrix with panel data

    Hi everyone,

    I have a panel data set, where I observe N individuals during T periods. I observe his wage and his age. I would like to create a NTxK matrix, where N (number of individuals) x T (number of periods) is the number of rows and K (the number of variables, in this case two: age and wage) is the number of columns.

    I am trying to do it with command mkmat but I am not able to get what I want.

    Anyone can give me help or some hints? Thank you in advanced!

    Best,

    Diego.

  • #2
    It should be easy enough if you have panel data. Consider the Grunfeld dataset with company=1, 2, ..., 5; time= 1, 2,..., 5.

    Code:
    webuse grunfeld
    keep if company<=5 & time<=5
    sort company time
    mkmat invest mvalue, mat(X)
    The above will give the the structure

    Click image for larger version

Name:	Untitled.png
Views:	1
Size:	8.2 KB
ID:	1608052


    where \(n=1, 2,\cdots, N; t=1, 2,\cdots, T\).

    Res.:

    Code:
    . mat l X
    
    X[25,2]
            invest     mvalue
     r1  317.60001     3078.5
     r2  391.79999  4661.7002
     r3  410.60001  5387.1001
     r4  257.70001     2792.2
     r5  330.79999  4313.2002
     r6  209.89999     1362.4
     r7  355.29999     1807.1
     r8  469.89999     2676.3
     r9  262.29999     1801.9
    r10  230.39999     1957.3
    r11  33.099998     1170.6
    r12         45     2015.8
    r13  77.199997     2803.3
    r14  44.599998     2039.7
    r15  48.099998     2256.2
    r16  40.290001      417.5
    r17  72.760002  837.79999
    r18  66.260002  883.90002
    r19  51.599998  437.89999
    r20      52.41  679.70001
    r21      39.68      157.7
    r22      50.73  167.89999
    r23  74.239998  192.89999
    r24  53.509998      156.7
    r25  42.650002  191.39999
    Last edited by Andrew Musau; 06 May 2021, 10:59.

    Comment


    • #3
      Thank you for your answer Andrew Musau. I appreciate it.

      I do not understand well why I should write command keep if company <= 5 and time <=5. If n = 1, 2, ..., 5 and t = 1, 2, ...3, is it obvious, right? I am sorry but I am learning about stata, I am a newbie.

      On the other hand, once I compute a matrix in stata, how can I see it?

      Best,

      Diego.

      Comment


      • #4
        Originally posted by Diego Malo View Post
        I do not understand well why I should write command keep if company <= 5 and time <=5. If n = 1, 2, ..., 5 and t = 1, 2, ...3, is it obvious, right?
        I do this to simplify the example. I started by stating,


        Consider the Grunfeld dataset with company=1, 2, ..., 5; time= 1, 2,..., 5.

        So I am just keeping the first 5 time periods and the first 5 companies.


        keep if company<=5 & time<=5


        Originally posted by Diego Malo View Post
        On the other hand, once I compute a matrix in stata, how can I see it?
        -matrix list matname- where matname is the name of your matrix. I do this in #2


        . mat l X

        X[25,2]
        invest mvalue
        r1 317.60001 3078.5
        r2 391.79999 4661.7002
        r3 410.60001 5387.1001

        See

        Code:
        help matrix list
        Last edited by Andrew Musau; 08 May 2021, 04:54.

        Comment


        • #5
          Ohh, I perfectly understand. Thank you so much!

          Comment

          Working...
          X