Announcement

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

  • Store p-values in a matrix after 'actest'

    Dear Statalist users,

    I am using the 'actest' command to conduct a serial correlation test after time-series regressions. However, I need to repeat the test 48 times (i.e., after each of the 48 regressions). So, I am trying to write a Stata code that generates the results automatically as follows:

    matrix autocorr=J(48,7,.)
    local i=1
    forvalues j = 1/48 {
    reg y x1 x2 x3 x4 if id==`j', robust
    actest, r q0 lag(1/3)
    matrix [`i',1]=(r(p))
    i=`i'+1
    }
    matrix list autocorr

    I get the message:
    matrix operation not found
    r(501);



    I need help on how to fix the issue.

    Thanks in advance for your reply.

    Emna

  • #2
    I believe you left out the matrix name from your matrix command.
    Code:
    matrix autocorr=J(48,7,.)
    local i=1
    forvalues j = 1/48 {
    reg y x1 x2 x3 x4 if id==`j', robust
    actest, r q0 lag(1/3)
    matrix autocorr[`i',1]=(r(p))
    i=`i'+1
    }
    matrix list autocorr
    Correcting this may expose subsequent issues, but this is a start at least.

    Comment


    • #3
      Dear William,

      Yes, that was missing, but the code still contains other errors though. It does not give me the output. I think that the issue is in the content of the matrix itself.

      I tried, however, this code. It gives results, but the format does not look good.

      Code.txt



      Emna
      Attached Files
      Last edited by Emna Trabelsi; 02 Aug 2020, 16:05.

      Comment


      • #4
        Please do not present code as an attachment - copy it and paste it into your post, using CODE delimiters as described in the Statalist FAQ linked to from the top of the page.

        Below is the code from your attachment.

        Code:
        forvalues j = 1/48 {
        forvalues k = 1/3 {
        reg y x1 x2 x3 x4 if id==`j', robust
        actest, r q0 lag(`k')
        matrix M=r(p)
        mat2txt, matrix(M) saving(C:\Users\Emna\Desktop\actest.txt) format(%12.3g) append
        }
        }
        Now you are creating 48*3 separate matrices each with one number in it. That is not likely to be helpful. Perhaps the following untested code will start you in a useful direction.

        Code:
        matrix M = J(48,3,.)
        forvalues j = 1/48 {
            forvalues k = 1/3 {
                reg y x1 x2 x3 x4 if id==`j', robust
                actest, r q0 lag(`k')
                matrix M[`j',`k'] = r(p)
            }
        }
        mat2txt, matrix(M) saving(C:\Users\Emna\Desktop\actest.txt) format(%12.3g) append

        Comment


        • #5
          Dear William,

          Thank you for your answer. I tried the following code. The format looks better.

          Code:
          forvalues j = 1/48 {
          forvalues k = 1/3 {
          reg y x1 x2 x3 x4 if id==`j', robust
          actest, r q0 lag(`k')
          matrix M=r(p)
          matrix rownames M=`j'
          matrix colnames M="p"
          mat2txt, matrix(M) saving(C:\Users\Emna\Desktop\actest.txt) format(%12.3g) append
          }
          }

          The result is as follows:
          Code:
              p    
          1            .723    
              p    
          1            .488    
              p    
          1            .444    
              p    
          2            .197    
              p    
          2             .41    
              p    
          2            .595    
              p    
          3            .308    
              p    
          3           .0705    
              p    
          3            .104    
              p    
          4             .25    
              p    
          4            .325    
              p    
          4            .518    
              p    
          5            .477    
              p    
          5            .391    
              p    
          5            .476    
              p    
          6            .778    
              p    
          6            .921    
              p    
          6            .983    
              p    
          7            .243    
              p    
          7            .452    
              p    
          7            .631    
              p    
          8            .694    
              p    
          8           .0603    
              p    
          8           .0656    
              p    
          9            .246    
              p    
          9            .085    
              p    
          9            .175    
              p    
          10           .0372    
              p    
          10           .0437    
              p    
          10           .0735    
              p    
          11            .409    
              p    
          11            .282    
              p    
          11            .374    
              p    
          12            .488    
              p    
          12            .705    
              p    
          12            .388    
              p    
          13            .573    
              p    
          13            .209    
              p    
          13            .298    
              p    
          14            .189    
              p    
          14           .0793    
              p    
          14            .165    
              p    
          15            .471    
              p    
          15            .372    
              p    
          15            .483    
              p    
          16            .297    
              p    
          16            .423    
              p    
          16            .627    
              p    
          17            .436    
              p    
          17            .561    
              p    
          17            .503    
              p    
          18            .166    
              p    
          18           .0685    
              p    
          18           .0973    
              p    
          19             .89    
              p    
          19            .716    
              p    
          19            .867    
              p    
          20           .0705    
              p    
          20            .178    
              p    
          20            .183    
              p    
          21            .188    
              p    
          21            .301    
              p    
          21            .459    
              p    
          22            .461    
              p    
          22            .719    
              p    
          22            .666    
              p    
          23            .174    
              p    
          23            .379    
              p    
          23            .461    
              p    
          24            .423    
              p    
          24            .725    
              p    
          24            .732    
              p    
          25            .302    
              p    
          25            .578    
              p    
          25            .774    
              p    
          26            .882    
              p    
          26           .0978    
              p    
          26            .113    
              p    
          27           .0679    
              p    
          27            .188    
              p    
          27            .318    
              p    
          28            .415    
              p    
          28            .715    
              p    
          28              .7    
              p    
          29           .0137    
              p    
          29           .0317    
              p    
          29           .0733    
              p    
          30            .217    
              p    
          30            .434    
              p    
          30             .63    
              p    
          31           .0922    
              p    
          31           .0318    
              p    
          31           .0529    
              p    
          32           .0123    
              p    
          32           .0425    
              p    
          32           .0954    
              p    
          33            .201    
              p    
          33            .386    
              p    
          33            .394    
              p    
          34           .0116    
              p    
          34           .0147    
              p    
          34           .0375    
              p    
          35            .615    
              p    
          35            .753    
              p    
          35            .707    
              p    
          36            .492    
              p    
          36             .77    
              p    
          36            .773    
              p    
          37           .0349    
              p    
          37           .0369    
              p    
          37            .052    
              p    
          38            .152    
              p    
          38            .297    
              p    
          38            .475    
              p    
          39            .897    
              p    
          39            .838    
              p    
          39            .689    
              p    
          40            .177    
              p    
          40            .402    
              p    
          40            .577    
              p    
          41             .79    
              p    
          41            .878    
              p    
          41            .466    
              p    
          42            .859    
              p    
          42           .0746    
              p    
          42           .0605    
              p    
          43            .558    
              p    
          43            .711    
              p    
          43            .853    
              p    
          44              .2    
              p    
          44             .36    
              p    
          44            .303    
              p    
          45            .134    
              p    
          45            .235    
              p    
          45            .274    
              p    
          46            .279    
              p    
          46             .55    
              p    
          46            .514    
              p    
          47            .572    
              p    
          47            .344    
              p    
          47            .536    
              p    
          48            .839    
              p    
          48            .819    
              p    
          48            .907
          I delete the repeated p by making this: select all, then replace "p" by " " (i.e., empty cell).

          FYI: The p-values are those of the test of the 'actest' serial correlation at specific lags k.

          Best,

          Emna
          Last edited by Emna Trabelsi; 03 Aug 2020, 03:30.

          Comment

          Working...
          X