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 or macro needed??? - Followup question


From   Jennifer A Hoff <[email protected]>
To   [email protected]
Subject   st: Looping or macro needed??? - Followup question
Date   Fri, 3 Jun 2011 10:28:19 -0400

OK I got the loop working  - Thanks Nick!


Next question is how to deal with making a log file

Do I put the log statement outside the loop and make one log file 
containing results of all 8 datasets?
Or do I put the log command inside of the loop and make a log file for 
each?

Neither seems to be working on my first attempts.
Is the clear command wiping out the log statement?



foreach s in aaa bbb ccc ddd eee fff ggg hhh {
       use  "P:\ProjectName \Mat070809_`s'.dta, clear
       ...
}

---------------------------------------------------------------------------------------------------------
Jennifer Hoff Lindquist
Statistician
Health Services Research and Development
Mailing Address: 
VA Medical Center
508 Fulton Street (152)
Durham, NC 27705
(919) 286-0411 Ext. 4054 (New as of 5/18/09)
[email protected]
[email protected]
---------------------------------------------------------------------------------------------------------

This communication and its attachments contain information from the Duke 
University Medical Center and/or Durham, NC, VA Medical Center and is 
intended for the exclusive use of the recipient(s) named above. It may 
contain information that is confidential and/or legally privileged. Any 
unauthorized use that may compromise that confidentiality via distribution 
or disclosure is prohibited by federal law. Please notify the sender 
immediately if you receive this communication in error and delete it from 
your computer system or destroy this document.
----- Forwarded by Jennifer A Hoff/HSRD/VA/mc/Duke on 06/03/2011 10:23 AM 
-----

Nick Cox <[email protected]> 
Sent by: [email protected]
06/02/2011 04:03 PM
Please respond to
[email protected]


To
[email protected]
cc

Subject
Re: st: Looping or macro needed???






A loop could be

foreach s in aaa bbb ccc ddd eee fff ggg hhh {
       use  "P:\ProjectName \Mat070809_`s'.dta, clear
       ...
}

Nick

On Thu, Jun 2, 2011 at 8:38 PM, Jennifer A Hoff
<[email protected]> wrote:
> I am running a regression and calculating a couple of difference in
> difference using data set Mat070809_aaa.
>
> Ie.    use "P:\ProjectName \Mat070809_aaa.dta"
>
> I have the do file up and working for this one dataset.
>
>
> I now need to repeat the same regression for 7 more data sets
> Mat070809_bbb, Mat070809_ccc, Mat070809_ddd, Mat070809_eee, 
Mat070809_fff,
>
> Mat070809_ggg, Mat070809_hhh
>
> I am a very new Stata user but it seems to beg for some type of looping 
or
>
> macro.
>
> Especially when I anticipate having to re-run each of the 8 regressions
> with 3 strata!  - Running 24 separate do files seems inefficient.
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index