Announcement

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

  • -putexcel- inserting rows within the 'results' block from within stata

    I want to output to excel to organize my mixlogit outputs. The code I have works well to write mixed logit to excel, but I do not know how to command Stata to insert a blank row in the middle of the 'matlist results' output without overwriting the results themselves. (I need to insert the blank row so that I can take the negative sum to get the third attribute: this is effects coded data). Any ideas on how to do this? My code below works well to export to stata, but not to add in the insert rows within the results:
    Click image for larger version

Name:	Screen Shot 2019-08-12 at 2.54.14 PM.png
Views:	1
Size:	125.2 KB
ID:	1511962


    ** Exporting results **
    mixlogit choice, group(resptask) id(respid) rand($varse) nrep(200)
    matlist r(table)
    matrix results = r(table)
    matrix results = results[1..6,1...]'
    matlist results
    putexcel set RegressionDCEDMD.xlsx, sheet(Mixlogit effects) replace
    putexcel A12 = matrix(results), names nformat(number_d2) hcenter
    putexcel A1=(e(title)) ///
    E1 = "Results last updated" G1 = "`c(current_date)'" ///
    A2=(e(cmdline)) ///
    A4=("Obs") B4=(e(N)) ///
    A5= ("Clusters") B5=(e(N_clust)) ///
    A6=("Wald chi2(df)") B6=(e(chi2)) ///
    A7= ("DF") B7=(e(df_m)) ///
    A8=("Prob>chi2") B8=(e(p)) ///
    A9 =("Psuedo R2") B9= (e(r2_p)) ///
    A10 = ("Log psuedolikelihood") B10= (e(ll))
    vce
    return list
    matrix list r(V)
    putexcel A37 = ("Covariance matrix of coefficients") ///
    C36 = matrix(r(V))


    Thank you!!

  • #2
    You could split up the matrix "results" into two parts and then add the formula in between the two matrices. So you change your code from
    Code:
    matrix results = results[1..6,1...]'
    ...
    putexcel A12 = matrix(results), names nformat(number_d2) hcenter
    to
    Code:
    matrix results = results[1..6,1...]'
    matrix results1 = results[1..2,1...]
    matrix results2 = results[3...,1...]
    putexcel A12 = matrix(results1), names nformat(number_d2) hcenter
    putexcel C15 = formula(-SUM(C13:C14))
    putexcel A16 = matrix(results2), rownames nformat(number_d2) hcenter
    These changes are not tested, but you should get the idea.

    Comment

    Working...
    X