Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
"William Buchanan" <william@williambuchanan.net> |

To |
<statalist@hsphsun2.harvard.edu> |

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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] 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/

**References**:**st: Need help with Programming multiple datasets***From:*Michael Stewart <michaelstewartresearch@gmail.com>

- Prev by Date:
**st: _docx() example error** - Next by Date:
**st: RE: xtnbreg - same results after convergence at 9,000 iterations or limiting to 100 iterations** - Previous by thread:
**Re: st: Need help with Programming multiple datasets** - Next by thread:
**st: outsheet and variable labels** - Index(es):