Announcement

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

  • to save results (matrix)

    Let's say i get the following result from running ardl on one panel group. What i want to save is the matrix at the end for all the panel units. So i created a loop (attached all the way at the end),


    . ardl ln_TX ln_REER ln_RGDP_P if (group==111), maxlag(3 3 3)

    ARDL regression
    Model: level

    Sample: 1983 - 2014
    Number of obs = 32
    Log likelihood = 31.878688
    R-squared = .97502017
    Adj R-squared = .97131945
    Root MSE = .09727648

    ------------------------------------------------------------------------------
    ln_TX | Coef. Std. Err. t P>|t| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    ln_TX |
    L1. | .7853204 .1002376 7.83 0.000 .57965 .9909909
    |
    ln_REER |
    --. | .2648877 .1892044 1.40 0.173 -.1233276 .653103
    L1. | -.4461474 .1843635 -2.42 0.023 -.8244301 -.0678647
    |
    ln_RGDP_P | .3999101 .1890194 2.12 0.044 .0120743 .7877459
    _cons | -1.958013 1.696903 -1.15 0.259 -5.439769 1.523744
    ------------------------------------------------------------------------------

    . matrix list e(lags)

    e(lags)[1,3]
    ln_TX ln_REER ln_RGDP_P
    r1 1 1 0





    Code:

    capture postutil clear
    postfile handle int group float ln_TX ln_REER ln_RGDP_P using ardl_lags, replace

    forvalues i = 1/2 {
    ardl ln_TX ln_REER ln_RGDP_P if (group==`i'), maxlag(3 3 3)
    matrix list e(lags)
    di
    post handle (`i') (e(lags))
    }
    postclose handle
    end




    How should i correct my code?
    What i want in my saved file is a list of panel ids and the matrices.

    i.e.

    id in_TX ln_REER ln_RGDP
    1 1 1 0
    2 2 2 2
    3 .
    4
    .
    .

  • #2
    Hi Olivia,

    sorry for the late response. You've probably figured out how to do this by now. Just to complete things, the following code snippet does what you want:

    Code:
    webuse grunfeld
    levelsof company , local(complist)
    capture matrix drop lagmat
    foreach comp of local complist {
        ardl invest mvalue if company==`comp'
        matrix lagmat = nullmat(lagmat) \ e(lags)
    }
    matrix rownames lagmat = `complist'
    matrix list lagmat
    You could also get your postfile approach working but I think you would have to wrap ardl into another program, since postfile only stores scalars and since Stata expressions (that one uses in the post command) cannot directly index into general matrices from r()/e() in order to produce such scalars. Such a thing has to be spread out over two lines of code. I find the above solution simpler.

    Best,
    Daniel

    Comment

    Working...
    X