Announcement

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

  • Dropping 0s in Matrices

    Note that I use synth from SSC. Consider the following
    Code:
    cls
    u "http://fmwww.bc.edu/repec/bocode/s/scul_basque.dta", clear
    
    qui xtset
    local lbl: value label `r(panelvar)'
    
    loc unit ="Basque Country (Pais Vasco)":`lbl'
    
    
    loc int_time = 1975
    
    qui xtset
    cls
    
    loc x 1961(1)1969
    
    loc y 1960(1)1969
    
    loc z 1964(1)1969
    
    
    
    tempfile scmbasque scmbasque2
    cls
    synth gdpcap /// classic SCM
        gdpcap(`y') ///
        pop(1969) ///
            sec_agriculture(`x') ///
            sec_energy(`x') ///
            sec_industry(`x') ///
            sec_construction(`x') ///
            sec_svc_venta(`x') ///
            sec_svc_nonventa(`x') ///
        school_illit(`z') ///
        school_prim(`z') ///
        school_med(`z') ///
        school_high(`z') ///
        invest(`z'), ///
        trunit(`unit') ///
        trperiod(`int_time') ///
        fig nested allopt keep(`scmbasque')
    
    
    mat li e(V_matrix)
    The resulting matrix
    Code:
    symmetric e(V_matrix)[13,13]
                  gdpcap~1969)     pop(1969)  sec_ag~1969)  sec_en~1969)  sec_in~1969)  sec_co~1969)  sec_sv~1969)
    gdpcap~1969)     .28494051
       pop(1969)             0     .08034821
    sec_ag~1969)             0             0     .01250346
    sec_en~1969)             0             0             0     .15639678
    sec_in~1969)             0             0             0             0     .15177799
    sec_co~1969)             0             0             0             0             0     .00277837
    sec_sv~1969)             0             0             0             0             0             0     .00470292
    sec_sv~1969)             0             0             0             0             0             0             0
    school~1969)             0             0             0             0             0             0             0
    school~1969)             0             0             0             0             0             0             0
    school~1969)             0             0             0             0             0             0             0
    school~1969)             0             0             0             0             0             0             0
    invest~1969)             0             0             0             0             0             0             0
    
                  sec_sv~1969)  school~1969)  school~1969)  school~1969)  school~1969)  invest~1969)
    sec_sv~1969)     .00466699
    school~1969)             0     .01746123
    school~1969)             0             0     .00170478
    school~1969)             0             0             0     .20263447
    school~1969)             0             0             0             0      .0674579
    invest~1969)             0             0             0             0             0     .01262639
    is a 13 by 13 revulsion that looks ugly to me. Shame on the coders for making it be like that- but enough ranting. My question is, how would I delete the 0s from this matrix such that we have something like
    Code:
                           Predictor | V Weight
    -----------------------------+------------
                       gdpcap~1969) |           .28494051
                          pop(1969) |           .08034821
    and so on and so forth for each predictor. A colleague wanted to know how to present the matrix in his paper, but, I wanted to show him a way that gives an informative, clear answer, and the present way the matrix looks is, to me, cumbersome. How might I tackle this?

  • #2
    The resulting matrix is a 13 by 13 revulsion that looks ugly to me. Shame on the coders for making it be like that
    To be fair to them, they are displaying the variance matrix which has a very specific structure. You have variances as the diagonal elements and the off-diagonal elements are covariances.

    Code:
    mat wanted= e(V_matrix)[1..., 1]
    forval i= 2/ `=colsof(e(V_matrix))'{
        mat wanted= wanted+e(V_matrix)[1..., `i']
    }
    mat colname wanted= variance
    Res.:

    Code:
    . mat l wanted
    
    wanted[13,1]
                   variance
    gdpcap~1969)  .28494051
       pop(1969)  .08034821
    sec_ag~1969)  .01250346
    sec_en~1969)  .15639678
    sec_in~1969)  .15177799
    sec_co~1969)  .00277837
    sec_sv~1969)  .00470292
    sec_sv~1969)  .00466699
    school~1969)  .01746123
    school~1969)  .00170478
    school~1969)  .20263447
    school~1969)   .0674579
    invest~1969)  .01262639

    Comment

    Working...
    X