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

From |
Jeph Herrin <junk@spandrel.net> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Re: Loop programming |

Date |
Thu, 07 May 2009 10:24:37 -0400 |

I have often wished that Stata locals (or scalars) could be specified as arrays. There are two ways I usually deal with this problem, depending on how many values I have, and how they are indexed. The first is to subscript a bunch of locals: local tsm1 = 1.2 local tsm2 = 1.5 local tsm3 = 4.5 . . . local tsm100=166.4 Typing them all in is tedious, but once there, they are easily checked and/or edited for accuracy. You can put these in a separate file and -include- that do file, which tidies things up and makes them accessible to other files. Then you can refer to them inside your loop with tsm`i' The other way is to put them in a matrix. delimiter ; matrix input TSM = ( 1 1.2 \ 2 1.5 \ 3 4.5 \ . . . 100 166.4 ); delimiter cr Which can be easier to work with in some situations, eg, if you don't know ahead of time how many values you will have, you can get the dimensions of the matrix, pull off the first column for indexing, etc. hope this helps, Jeph Sherriff, Martyn wrote:

Sacrificial Sacrificial Sorry - forgot the truncated line problem I have an analysis where I need to compare a set of repeat measurements to a known standard value and then visualise the data in a stripplot with the standard value as a reference line, and this is repeated over several different systems and each system has a different standard value. Eventually there will be in excess of 100 systems. I have used a simple forvalues loop for this, but my problem is how to get the standard values into the loop. My crude and inefficient solution is to add standard values to the dataset, calculate their mean value, and then use this as the reference. set more off forvalues i=1/7{ di "`: label (sys) `i''" qui{ su ts if sys==`i' local tsm=r(mean) } ttest m=`tsm' if sys==`i' stripplot m if sys==`i',over(bn) vert bar stack separate(set) title("`: label (sys) `i''") yline(`tsm') } set more on Is there a straight forward method of getting these standard values into the loop? Eventually there will be in excess of 100 systems. Many thanks, Martyn * * 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/

* * 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/

**References**:**st: Re: Loop programming***From:*"Sherriff, Martyn" <martyn.sherriff@kcl.ac.uk>

- Prev by Date:
**st: RE: Re: Loop programming** - Next by Date:
**Re: st: St: Ordered Logit Question** - Previous by thread:
**st: RE: Re: Loop programming** - Next by thread:
**st: tsset with non-integers** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |