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]

Re: st: Need help with Programming multiple datasets


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Need help with Programming multiple datasets
Date   Sun, 2 Jun 2013 17:23:21 +0100

Sorry; previous was premature.

Nick
[email protected]

 Fewer capitals please (Google "email capitals shouting" if you don't
understand why).

Your two problems are really the same. You want a wildcard for a
variable list that includes every variable desired, but no more.

Reading the help for -varlist- suggests wildcards

DX? DX??

and

DXCCC? DXCCC??

so that your code could be (for example)

foreach v of var DX? DX?? {
icd9 generate diag_`v' =  `v', range("xxx.x")
}

A slightly more subtle approach:

unab DX : DX? DX??
local DX : subinstr local DX "DX" "", all

foreach n of local DX {
 icd9 generate diag_`n' = DX`n', range("xxx.x")
}

On 2 June 2013 16:40, Michael Stewart <[email protected]> wrote:

>> NEW PROBLEM-1:
>> If I want to run a forvalues loop in local "a" OR local "b"  FOR ONLY
>> DX1-15(for auto_1 ) OR DX1-25(auto_2) OR DX1-35(auto_3) BUT SHOULD NOT
>> LOOP OVER ANY OTHER SIMILAR VARIABLES like DXCCS1 DXCCS2   etc
>>
>> How can I modify my present forvalues loop to INCLUDE VARYING NUMBER
>> OF DX* VARIABLES
>> My present loop is
>>
>> forvalues y=2/15{
>> icd9 generate diag_`x'=DX`x', range("xxx.x")
>> }
>>
>> NEW PROBLEM-2:
>>
>> If I want to run a forvalues loop in local "a" OR local "b"  FOR ONLY
>> DXCCS1-15(for auto_1 ) OR DXCCS1-25(auto_2) OR DXCCS1-35(auto_3) BUT
>> SHOULD NOT LOOP OVER ANY OTHER SIMILAR VARIABLES like DX1 DX2   etc
>>
>> How can I modify my present forvalues loop to INCLUDE VARYING NUMBER
>> OF DX* VARIABLES
>> My present loop is
>> forvalues y=2/15{
>> icd9 generate diag_`x'=DX`x', range("xxx.x")
>> }
>>
>>
>> IF FOREACH LOOP is better , please  let me know the appropriate code
*
*   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