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: how to have commands in a loop (over strings) shown in log files, without using nested quotes


From   Xinjia Liu <[email protected]>
To   [email protected]
Subject   st: how to have commands in a loop (over strings) shown in log files, without using nested quotes
Date   Tue, 7 Aug 2012 12:03:46 -0400

Hi,
(sorry about previous email. first time user, wrong address used.)

I am trying to run a command with several different "if" conditions,
and have both the commands and the results shown in a log file.
The resulting log I want are like this...

log using...
table var1 var2 if var3 == "a", c(n var4)
(...the resulting table...)

table var1 var2 if var3 == "b", c(n var4)
(...the resulting table...)

table var1 var2 if var3 == "", c(n var4)
(...the resulting table...)
log close

If I use a loop to avoid typing the command repeatedly...

foreach val in "a" "b" "" {
table var1 var2 if var3 == "`val'", c(n var4)
}

The problem with the loop is, only the resulting table would show in
the log file, not the actual command.

log using...
...table 1...
...table 2...
...table 3...
log close

If I try to do

log using...
foreach ... {
display "cmd..."
cmd...
}
log close

I would need to somehow (e.g. using `"') include double quotes in the
cmd string, which could very easily introduce bugs that are hard to
fix.

I'm wondering if there is a way to produce these log files without
having to type each individual command or going into the whole double
quotes inside of a string issue.

Any help and comments would be greatly appreciated.

Thanks,
Xinjia
*
*   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