Statalist


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

Re: AW: st: AW: Flexible end of numlist


From   "Eric A. Booth" <[email protected]>
To   [email protected]
Subject   Re: AW: st: AW: Flexible end of numlist
Date   Thu, 13 Aug 2009 10:08:10 -0500

Obviously it doesn't. I didn't read that part of Michael's post carefully, and so my suggestion was simply aimed at making the end of his numlist flexible ... apologies to Michael for any confusion it might have caused.


Best,
Eric


__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249


On Aug 13, 2009, at 9:47 AM, Martin Weiss wrote:


<>

Well, I wanted to leave open the possibility that he might tweak my code to accomodate his stated wish that "the end of the numlist should be half the
number of the variables involved in that loop." How does your proposal
address this issue?




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Eric A. Booth
Gesendet: Donnerstag, 13. August 2009 16:45
An: [email protected]
Betreff: Re: st: AW: Flexible end of numlist

MIchael may not want to pass the -forvalues- loop a value from another
-local-, in which case using "  `=_N'  "  could do the trick:

*****

forvalues i=2/`=_N'  {
	di in red `i'
}
*****


Best,

Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249


On Aug 13, 2009, at 2:31 AM, Martin Weiss wrote:


<>

The help advises against this use of the -foreach- loop structure.
See -h
foreach-:" If you wish to loop over many equally spaced values, do not code...", instead use -forvalues-. Apart from that, you can have Stata
evaluate an -expression- as the endpoint of a -numlist-, in this
particular
case half the -local- "r":


*************
local r 10

forv i=1/`=`r'/2'{
	di in red `i'
}
*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Michael
Stuetzer
Gesendet: Donnerstag, 13. August 2009 02:40
An: [email protected]
Betreff: st: Flexible end of numlist

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/


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


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



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