Bookmark and Share

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]

Re: st: Need help with Programming multiple datasets


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Need help with Programming multiple datasets
Date   Sun, 2 Jun 2013 17:23:21 +0100

Sorry; previous was premature.

Nick
njcoxstata@gmail.com

 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 <michaelstewartresearch@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index