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]
st: RE: Need help with Programming multiple datasets
From
"William Buchanan" <[email protected]>
To
<[email protected]>
Subject
st: RE: Need help with Programming multiple datasets
Date
Tue, 25 Jun 2013 10:48:16 -0700
Have you looked through the help files for the -forvalues-, -foreach-, and
-if- commands? It would probably be more useful if you explain with some
type of example what it is that you are trying to accomplish explicitly. In
both of your questions, you're referencing a local macro that was previously
defined as storing file names (not variable names). In the second question,
if your variables are DXCCS# then there wouldn't be a way that DXCCS`number'
would evaluate to DX`number'.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael Stewart
Sent: Sunday, June 02, 2013 8:40 AM
To: statalist
Subject: st: Need help with Programming multiple datasets
Need help with Programming multiple datasets
Dear Statalist user ,
I need help with stat porgramming.
I am working with multiple datasets and with the help of statalist users,
was able to figure out a way to use multiple datasets, complete data
management tasks and save them under separate files
MY DATA STRUCTURE:
***************************************************************
auto-1 contains variables DX1-DX15; variables DXCCS1-DXCCS-15 + OTHER
VARIABLES
auto-2 contains variables DX1-DX25 ; variables DXCCS1-DXCCS-25 + OTHER
VARIABLES
auto-3 contains variables DX1-DX35 ; variables DXCCS1-DXCCS-35 + OTHER
VARIABLES
****************************************************************
My current code is as follows
***********************************************
local ds1 "D:\_Dummy\multiple\1\auto_1.dta"
local ds2 "D:\_Dummy\multiple\2\auto_2.dta"
local ds3 "D:\_Dummy\multiple\3\auto_3.dta"
local all ds1 ds2 ds3
foreach x in `all'{
use ``x'',clear
include "D:\_Dummy\multiple\4\a.do"
include "D:\_Dummy\multiple\5\b.do"
save ``x''_new.dta,replace
}
***********************************************
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
I thank in advance for all your help.
--
Thank you ,
Yours Sincerely,
Mike.
*
* 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/
*
* 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/