Announcement

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

  • putexcel with matrice value

    Hello,

    I'm bootstrapping a crosstab within a loop. Part of the results of that process is a matrice r(table)[9,3] as return list. Within the loop I want to put some values of this matrice into Excel. I know that the results are in column 1 row 1, column 1 row 4, column 2 row 1 and column 3 row 4. So I tried to integrate these matrice in the putexcel command but it doesn't work. I once used the code with matrice and it workde perfect, so all I need to know is how to say putexcel that I want a value from a matrice into a single Excel cell, starting with: putexcel C`row'=(r(table)[1,1]) as you can see below.
    Thanks, Nick.

    local row=2
    foreach x of varlist a b c d {
    bootstrap r(p) r(gamma) r(p_exact), reps(500) : tabulate varXYZ `x', chi2 exact gamma nofreq
    local varlabel : var label `x'
    putexcel A`row'=("`x'")
    putexcel B`row'=("`varlabel'")
    putexcel C`row'=(r(table)[1,1])
    putexcel D`row'=(r(table)[1,4])
    putexcel E`row'=(r(table)[2,1])
    putexcel F`row'=(r(table)[3,4])
    local ++row
    }

  • #2
    Got it myself using locals

    local row=2
    foreach x of varlist a b c d {
    bootstrap r(p) r(gamma) r(p_exact), reps(500) : tabulate varXYZ `x', chi2 exact gamma nofreq
    matrix b=r(table)
    local a=b[1,1]
    local b=b[4,1]
    local c=b[1,2]
    local d=b[4,3]
    local varlabel : var label `x'
    putexcel A`row'=("`x'")
    putexcel B`row'=("`varlabel'")
    putexcel C`row'=(`a')
    putexcel D`row'=(`b')
    putexcel E`row'=(`c')
    putexcel F`row'=(`d')
    local ++row
    }

    Comment

    Working...
    X