Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Maarten Buis <maartenlbuis@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Re: your response to stata list |

Date |
Wed, 25 Jul 2012 09:49:06 +0200 |

It is convention on Statalist to ask follow up question on the list and not privately, that way that part of the discussion will also be available in the archive. The reason for the error message is that you cannot have a -mata- <stuff> -end- session inside a Stata loop. What you can do is put the Mata commands inside a Mata function and inside the Stata loop call -mata you_mata_function()-. See: <http://www.stata.com/statalist/archive/2011-01/msg00393.html>. However, I think the easier solution for you would be to use Roger Newson's -parmby- command, which is part of the -parmest- package. *--------------- begin example --------------- // get the -parmby- command // I have it already so it is commented out *ssc install parmest sysuse cancer, clear stset studytime, failure(died) parmby "stcox age", by(drug) eform norestore list *--------------- end example ----------------- Also see: Roger B. Newson (2012) "From resultssets to resultstables in Stata". The Stata Journal, 12(2): 191-213. <http://stata-journal.com/article.html?article=st0254> Roger B. Newson (2003) "Confidence intervals and p–values for delivery to the end user". The Stata Journal, 3(3):245-269. <http://stata-journal.com/article.html?article=st0043> Hope this helps, Maarten On Tue, Jul 24, 2012 at 10:09 PM, yaacov lawrence wrote: > thank you for your rapid response on stata-list. > your code works wonders, but I have now the problem of incorporating mata > code into a stata do file. > for some reason the code below does not work. > the code should go through each value of "newgroup", performing a cox > analysis and filling the p values and HR into a matrix. > for some reason the loop gets stuck, possible by the word 'end' > I confess to feeling very out of my depth.... > ------------ > > egen newgroup = group(new_fips) > sum newgroup > matrix results = J(`r(max)',5,.) > matrix colnames results = group zipcode #patients HR P-value > > *go though each zip code and see how they improved over time (i.e. run a > cox analysis) > foreach i of num 1/`r(max)' { > matrix results[`i',1]=`i' > > quietly sum fips if group==`i' > matrix results[`i',2]= r(mean) > > quietly count if group==`i' > matrix results[`i',3]= r(N) > > stcox year_group if newgroup==`i' > > mata > b = st_matrix("e(b)") > V = st_matrix("e(V)") > hr = exp(b) > se = diagonal(cholesky(diag(V)))' > z = b:/se > p = 2*normal(-abs(z)) > st_numscalar("HR",hr) > st_numscalar("P",p) > end > > > matrix results[`i',4]= HR > matrix results[`i',5]= P > } > > matrix list results > > -- -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: RE: How to drop individuals from sample?** - Next by Date:
**Re: st: Meta-analysis of AUC curves developed using different type of regression models** - Previous by thread:
**st: How to drop individuals from sample?** - Next by thread:
**st: ylines with two y-axes** - Index(es):