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]

st: Looping through parallel lists


From   "Thirukumaran, Caroline Pinto" <[email protected]>
To   [email protected]
Subject   st: Looping through parallel lists
Date   Tue, 18 Mar 2014 16:02:50 -0400

Hi,

I have several repetitive blocks of code like the ones below. How can
I use  -foreach- or -forvalues- commands for shortening such blocks of
code?

Example:
use "$filepath\Cardiac.dta", clear
codebook case_number
reshape wide cardiac_icd9 cardiac_icd9description, i(case_number) j(countvar)
tab op_year
save "$filepath\Cardiac.dta", replace

use "$filepath\Concurrent.dta", clear
codebook case_number
reshape wide cpt_con cpt_condescription, i(case_number) j(countvar)
tab op_year
save "$filepath\Concurrent.dta", replace

The difference in the two blocks lies in line 1 (filename), 3 (list of
multiple variables) and 5 (filename) of each block. I am using Stata
12.1 for Windows

Many thanks in advance,
Caroline
*
*   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