Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: display commands generated within foreach-loop


From   Thorsten Faas <[email protected]>
To   [email protected]
Subject   Re: st: display commands generated within foreach-loop
Date   Tue, 20 Nov 2007 10:21:50 +0100

Thanks, Maarten - that works perfectly.

Maarten buis wrote:
--- Thorsten Faas <[email protected]> wrote:
how can I actually *see* the commands generated by a foreach-loop.

Let's say I have the following:

preserve
sysuse auto, clear
foreach x in "mpg" "price" {
	ttest `x', by(foreign)
}
restore


In this case, I would like to see

ttest mpg, by(foreign)

... output ...

ttest price, by(foreign)

... output ...

in my logfile, but I don't. All I see is the output of the T-test.
what about:

sysuse auto, clear
foreach x in "mpg" "price" {
di _n as input ". ttest `x', by(foreign)"
ttest `x', by(foreign)
}

The _n in the -di- command results in a new line, and the -as input- in
the -di- command makes sure that the string is displayed as input, and
the string is the command you are giving Stata.

-- Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ *
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index