Statalist


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

st: Flexible end of numlist


From   Michael Stuetzer <michael.stuetzer@qut.edu.au>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Flexible end of numlist
Date   Thu, 13 Aug 2009 10:39:43 +1000

Dear stata listers,

I need to program a loop and want to use the "foreach i of numlist 1/10" begin. However I want to have the end of numlist not to be fixed, but more flexible. To be more precise, the end of the numlist should be half the number of the variables involved in that loop. Does anyone have an idea how to do that?

The variables which are involved in that loop  are for instance pat_se1 pat_se2 pat_se3 pat_se4 and contain the month (pat_se[odd]) and the years (pat_se[even]) of a specific business starting activity.  I have here a first draft of that loop


foreach i of numlist 1/2 {
local j=`i'*2
local k=`j'-1
local t=round(`i'/2)
gen PATENTS_SH`i' = ym(pat_se`j', pat_se`k')
format PATENTS_SH`i' %tmn_CY
if mod(`i',2)==0 {
lab var PATENTS_SH`i' "Patenting, end `t'. spell, real time"
}
else lab var PATENTS_SH`i' "Patenting, start `t'. spell, real time"
}

Thanks for your help
Michael


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



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