Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Battling Mata docx commands - automation?


From   "Stephen Kay (TRUELIFE)" <Stephen.Kay@completetruelife.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Battling Mata docx commands - automation?
Date   Thu, 3 Oct 2013 09:33:58 +0000

Hi,

I'm running numerous regressions all with the same predictors but varying via the dependent variable. A simple example of what I'm managed to achieve is below:

sysuse auto,clear
label variable mpg "Miles Per Gallon"
label variable price "Price (£'s)"

foreach var of varlist mpg price {
	regress `var' foreign headroom
	mat define r_table = r(table)'
	matselrc r_table `var'Betas,  c(1/6) // might need to download associated ado 
}

mata
dh = _docx_new() 
_docx_paragraph_new_styledtext(dh, "Miles Per Gallon", "Heading1")
tid = _docx_add_matrix(dh, "mpgBetas", "%8.4f", 1, 1)
_docx_table_mod_cell(dh, tid, 2, 1, "Foreign")
_docx_table_mod_cell(dh, tid, 3, 1, "Headroom")
_docx_table_mod_cell(dh, tid, 4, 1, "Constant")

_docx_paragraph_new_styledtext(dh, "Price (£'s)", "Heading1")
tid = _docx_add_matrix(dh, "priceBetas", "%8.4f", 1, 1)
_docx_table_mod_cell(dh, tid, 2, 1, "Foreign")
_docx_table_mod_cell(dh, tid, 3, 1, "Headroom")
_docx_table_mod_cell(dh, tid, 4, 1, "Constant")
res = _docx_save(dh, "Laborious Method.docx")
end

I'm trying to write a Mata function which I can call from my foreach loop so I can do away with having to write individual mata code for each dependent variable (as in the example above). The function would take the dependent variable's label to use as a heading and Beta matrix. It's defeated me. Can anyone provide code to do such? Any help much appreciated - even knowing it can't be done.

Many thanks, 

Steve Kay


This email may contain confidential or legally privileged information, intended only for the addressee.
If you have received this email in error, you are hereby notified that any disclosure, copying, distribution or reliance upon the contents of this email is strictly prohibited. Please contact the sender to arrange for correct delivery, and then delete this email.

Any views or opinions presented in this email are those of the author. Please check the email for viruses, as the sender accepts no liability for damage caused by a virus transmitted via this email.

Registered Office: McCann Complete Medical Ltd. Complete House, 19-21 King Edward Street, Macclesfield, Cheshire SK10 1AQ, UK
Tel: +44 (0)1625 624000, Fax: +44 (0)1625 619812, Email: enquiries@complete-grp.com, Web: www.complete-grp.com
Registered in England No. 2503062

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index