Announcement

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

  • change matrix column name

    Dear STATA users,

    I have 11 matrix that I would like to change their row names. For example, one of the matrices looks like the following:

    HTML Code:
    . mat list tau5
    
    tau5[1,4]
    /:          /:    /:    /:
    _cons       _cons    _cons    _cons
    b  -.68602625  -.38464392    .33052216    1.0841271

    I’d like to change column equation names by giving each cell more explicit indexes.
    I could do this manually as following :

    Code:
      mat coleq tau2 = tau2_1 tau2_2 tau2_3 tau2_4 tau2_5 tau2_6 tau2_7 tau2_8 tau2_9
      mat coleq tau3 = tau3_1 tau3_2 tau3_3
      mat coleq tau4 = tau4_1 tau4_2 tau4_3
      mat coleq tau5 = tau5_1 tau5_2 tau5_3 tau5_4
      mat coleq tau6 = tau6_1 tau6_2
      mat coleq tau7 = tau7_1 tau7_2 tau7_3 tau7_4 tau7_5 tau7_6 tau7_7 tau7_8 tau7_9
      mat coleq tau8 = tau8_1 tau8_2 tau8_3
      mat coleq tau9 = tau9_1 tau9_2 tau9_3 tau9_4
      mat coleq tau10 = tau10_1 tau10_2 tau10_3
      mat coleq tau11 = tau11_1 tau11_2 tau11_3
      mat coleq tau12 = tau12_1 tau12_2 tau12_3

    However, I wonder if there's a simpler way that I can automate this routine?


  • #2
    This should do it.

    Code:
    forval i= 2/12{
    local n= `= colsof(tau_`i')'
    local ctau`i' ""
    forval j=1/`n'{
    local ctau`i' "`ctau`i'' tau`i'_`j'"
    }
    mat coleq tau_`i'= `ctau`i''
    }

    Comment


    • #3
      Thanks a lot Andrew !

      Comment

      Working...
      X