Announcement

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

  • Merging estimate matrix with loop

    Hello:

    I am trying to merge multiple Cox estimates as a matrix (for a forest plot after this). Below I have 3 variables as an example with 3 estimates. How do I have a single merged matrix that holds/joins up as many matrices as the number of variables held in the first local with the list of variables? I can of course merge manually like I did (matc below), but I am going to have to do nearly 30 separate models to export and needed a little more automation to accommodate as many univariate models as possible without having to specific m1 through m30.

    Code:
        * OS24 analysis:
    stset docens, fail(dead)                 origin(time dodx)                     ///
                                            enter(time dodx)                     ///
                                            exit(time dodx + 24 * 30.455)         ///
                                            scale(30.455)
    
    
    matrix drop _all
    local vars age70 anymis ep6
    local i = 0
    foreach var of local vars{
        local i = `i'+1
        stcox `var'
        mat m`i' = r(table)
    }
    
    mat c = m1, m2, m3

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int(dodx docensor) long dead float age70 byte anymis float ep6
    20578 20739 1 0 1 0
    20671 20721 1 1 0 0
    20773 20852 1 0 1 0
    21124 21729 1 0 1 0
    21293 21713 1 0 1 0
    21411 21543 1 1 1 1
    21780 21920 1 1 1 1
    21829 22099 1 1 1 1
    21900 22027 1 1 1 0
    22001 22308 1 1 1 1
    22095 22171 1 1 0 1
    20285 20334 1 1 1 1
    22145 22160 1 1 1 0
    22171 22204 1 1 1 1
    22201 22301 1 1 1 1
    21216 22546 1 0 1 0
    20362 20399 1 0 0 0
    20419 20534 1 0 1 0
    22524 22644 1 1 1 0
    20301 20444 1 0 0 0
    22680 22905 0 0 1 0
    22736 22777 1 0 1 1
    22848 22996 1 1 1 1
    22841 22864 1 1 1 1
    20508 20601 1 1 1 1
    20159 20464 1 0 1 0
    20850 21043 1 0 0 0
    20885 21139 1 0 1 0
    21455 21901 1 0 1 0
    20936 21397 1 0 1 1
    20969 21267 1 0 1 1
    21082 21353 1 1 1 0
    20816 21047 1 0 1 0
    20083 20116 1 0 1 0
    21304 21403 1 0 1 0
    21105 23086 0 1 1 0
    20109 20541 1 0 1 1
    19991 20907 1 1 1 0
    21173 21267 1 0 1 1
    21158 21203 1 0 1 1
    21249 21428 1 1 1 0
    21249 21595 1 1 1 0
    20137 20673 1 1 0 0
    21922 21962 1 1 0 0
    21093 21443 1 0 1 1
    21366 21544 1 0 1 1
    20137 20946 1 0 1 0
    21419 21609 1 0 0 1
    21346 22359 1 1 1 0
    20171 20377 1 0 0 0
    21511 22123 1 1 1 0
    21567 21974 1 1 1 0
    21444 21608 1 0 1 1
    21626 23070 0 1 1 0
    20730 21948 1 0 1 0
    21719 21973 1 0 1 1
    21764 21841 1 0 0 1
    21797 21806 1 0 0 0
    21856 22885 1 1 1 0
    21850 21933 1 0 1 1
    21916 22125 1 1 1 0
    21366 21948 1 0 1 1
    21931 22424 1 0 1 0
    21962 22162 1 1 1 1
    21992 22078 1 1 1 0
    22371 22829 1 0 1 0
    21993 22344 1 0 1 0
    20280 20868 1 0 1 0
    22103 23092 0 0 0 0
    20293 20698 1 1 1 0
    21959 22237 1 0 1 1
    22203 22509 1 0 1 0
    22200 22433 1 1 1 0
    20328 21806 1 0 1 0
    22343 22720 1 1 1 1
    22434 22496 1 1 1 1
    20887 22427 1 0 1 0
    20891 22698 1 0 1 0
    22532 23090 0 0 1 0
    22559 22708 1 1 1 1
    21342 22437 1 1 1 1
    20270 21455 1 0 1 0
    20458 20518 1 1 1 1
    22720 22818 1 1 1 0
    22725 22899 1 0 0 0
    20558 20667 1 1 0 1
    21062 21111 1 1 0 1
    21279 21314 1 0 0 0
    21334 21715 1 0 1 0
    21601 21634 1 1 0 1
    22286 22367 1 1 0 0
    22517 22760 1 1 1 1
    18226 20612 1 0 1 1
    20433 20580 1 0 0 0
    19540 20939 1 0 1 0
    20773 21273 1 1 1 0
    20789 20885 1 0 0 0
    20816 21205 1 0 1 0
    20969 21010 1 1 1 0
    21271 21588 1 0 1 0
    end
    format %tdnn/dd/CCYY dodx
    format %tdnn/dd/CCYY docensor
    label values dead deadlab
    label def deadlab 0 "Alive", modify
    label def deadlab 1 "Dead", modify
    label values age70 age70lab
    label def age70lab 0 "<=70yrs", modify
    label def age70lab 1 ">70 yrs", modify
    label values anymis anymis
    label def anymis 0 "No TP53-Missense", modify
    label def anymis 1 "Any TP53-Missense", modify
    label values ep6 apalab
    label def apalab 0 "Absent", modify
    label def apalab 1 "Present", modify

  • #2
    Code:
    local vars age70 anymis ep6
    foreach var of local vars{
        stcox `var'
        matrix M = nullmat(M), r(table)
    }
    
    matrix list M

    Comment


    • #3
      Thanks much, Clyde Schechter Just read up that -nullmat- is a matrix function. The code worked beautifully, as it always does with your codes.

      Comment

      Working...
      X