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: RE: Loop over a list of strings with logs


From   Kieran McCaul <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Loop over a list of strings with logs
Date   Thu, 30 Jan 2014 04:11:04 +0800

...

The file name in the log statement should be enclosed in quotes and use "/" rather than "\" in the path.

    log using "C:/stata/`i'_results.txt", text replace

The error is being caused by:
    keep if school==`i'
This should be:
    keep if school=="`i'"


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Brandon Olszewski
Sent: Thursday, 30 January 2014 3:56 AM
To: [email protected]
Subject: st: Loop over a list of strings with logs

I am using Stata 12. I have a list of schools that I want to loop some commands over, including logging output. I have consulted the
"Speaking Stata:  How to face lists with  fortitudeQ2/02   SJ
2(2):202--222" article and searched the list, but I am still mystified. This is what I want to do:

I have a list of schools (var = school, string format), call them "adams" "billings" and "charles". I want to perform the following operations that will yield by school results: start a log that is named for the respective school, keep observations only for one school, display the school's name, tab responses to item1 and item2, and close the log. I think it should be something like this:

foreach i in adams billings charles {
    preserve
    log using "C:\stata\`i'_results.txt, text replace
    keep if school==`i'
    di in r school
    tab item1
    tab item2
    log close
    restore
    }

I know I can also do something like:

local schools "adams billings charles"
foreach i in `schools' {
   preserve
   etc...
   }

When I try anything, Stata tells me that "adams not found".

I would really appreciate any help. I know I've done this before, but just don't see what I'm doing wrong. Thanks.
*
*   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/


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