Announcement

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

  • Construct a matrix of control variables

    Hello,

    I am new to stata so please pardon me.

    I want to construct a matrix of control variables using three different variables. If anyone can help on how to go about this kindly advise.

    Thank you.

  • #2
    Hi Stephanie,

    I'm wondering what exactly do you want to do. Do you want to run a regression with these three variables.. or?

    I'm asking because most-likely-than-not new users don't tend to start with Mata (the matrix programming language, in which forum you are on) but with more standard Stata commands.

    Best,
    S

    Comment


    • #3
      Originally posted by Sergio Correia View Post
      Hi Stephanie,

      I'm wondering what exactly do you want to do. Do you want to run a regression with these three variables.. or?

      I'm asking because most-likely-than-not new users don't tend to start with Mata (the matrix programming language, in which forum you are on) but with more standard Stata commands.

      Best,
      S
      Hi Sergio,

      Thank you for your response.

      Yes, I want to run a regression (GMM) with the matrix that contains these three variables.

      Comment


      • #4
        Stata:

        Code:
        sysuse auto, clear
        keep in 1/10
        mkmat mpg weight displacement, matrix(X)
        mat list X
        Mata:

        Code:
        sysuse auto, clear
        keep in 1/10
        mata
        X = st_data(.,("mpg", "weight", "displacement"))
        X
        end

        Res.:

        Code:
        . mkmat mpg weight displacement, matrix(X)
        
        . mat list X
        
        X[10,3]
                      mpg        weight  displacement
         r1            22          2930           121
         r2            17          3350           258
         r3            22          2640           121
         r4            20          3250           196
         r5            15          4080           350
         r6            18          3670           231
         r7            26          2230           304
         r8            20          3280           196
         r9            16          3880           231
        r10            19          3400           231
        
        . mata
        ------------------------------------------------- mata (type end to exit) ----------------------------------------------------------
        : X = st_data(.,("mpg", "weight", "displacement"))
        
        : X
                   1      2      3
             +----------------------+
           1 |    22   2930    121  |
           2 |    17   3350    258  |
           3 |    22   2640    121  |
           4 |    20   3250    196  |
           5 |    15   4080    350  |
           6 |    18   3670    231  |
           7 |    26   2230    304  |
           8 |    20   3280    196  |
           9 |    16   3880    231  |
          10 |    19   3400    231  |
             +----------------------+
        
        : end
        ------------------------------------------------------------------------------------------------------------------------------------

        Comment

        Working...
        X