Announcement

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

  • Concatenating matrices in putexcel

    I am currently using Stata 14 and attempting to use putexcel to write svy: tab results to Excel in table format.

    I have no problem returning stored results from matrices using estpost, as follows:

    Code:
    estpost svy: tab var
    mat B = e(b)
    mat C = B'
    mat D = C*100
    putexcel (B3) = matrix(D), nformat(0.0)
    I am however keen to write the confidence intervals for this estimation to putexcel, formatted correctly for a publication table as (lb-ub). I have not been able to work out how to do this using matrix functions. I can return the confidence interval in separate columns, using the follow:

    Code:
    estpost svy: tab estudio_cat
    mat E = e(lb)
    mat F = E'
    mat G = F*100
    mat H = e(ub)
    mat I = H'
    mat J = I*100
    mat K = G,J
    putexcel (D3) = matrix(K), nformat(0.0)
    However, I am keen to format this as described above.

    This is my first time posting on here, I hope that I have correctly followed the conventions and provided sufficient information. This solution to this has eluded me for quite some time.

    Thanks,

  • #2
    Solved.

    I was able to solve this by first transposing the matrices for the required outputs (e(lb), e(ub)) and sequentially outputting each table row based on row counts (e(r)).
    The relevant matrices for each row were then multiplied by 100 (output table preference only) and converted to string variables (UBS, LBS) which were concatenated with a dash, stored in a local macro, to obtain the desired output - LCI-UCI.


    Code:
    estpost svy: tab `myvar'
    mat E = e(lb)
    mat F = E'
    mat G = e(ub)
    mat H = G'
    
    local rows = e(r)
    forvalues i = 1/`rows' {
    local UB = round(100*H[`i',1],.1)
    local UBS = string(`UB',"%3.1f")
    local LB = round(100*F[`i',1],.1)
    local LBS = string(`LB',"%3.1f")
    local dash = "-"
    local CIS = `"`LBS'`dash'`UBS'"'
    putexcel (C`row') = "`CIS'"
    I hope this may be useful to others in the future. There may be a more elegant solution.

    Comment

    Working...
    X