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]
Re: st: really silly question
From
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: really silly question
Date
Tue, 8 Mar 2011 14:03:26 +0000
<>
I read Scott's question a different way. I thought Scott was asking for a way to write a (interactive) program that runs some command (here -tab- is his example) repeatedly, but asking for user input (of two variables x and y) in the command window each time until the user says stop. The way I know to do this is by using -display- with the 'request()' option (see -help display-). So, Scott's program might look like:
**************!
cap program drop rerun
program def rerun
syntax varlist(min=2 max=2 numeric)
token `"`varlist'"'
tab `1' `2', col V w nokey miss
noi di `"Enter 2 more vars to -tab- (or type STOP to exit program):"', _request(answer)
if `"$answer"'=="STOP" exit
unab totab: $answer
rerun `totab'
end
**********
*where the user would run from the command line:
sysuse auto, clear
keep in 1/10 //to keep the tab results manageable
rerun for rep78
*user input: turn rep
*user input: price for
*and so on....
*user input: STOP
**************!
I'm not sure why Scott would want a program that does this (maybe it's for some kind of interactive demo of the command window for students, he wants something like "display foo, _request(bar)" for a part of another program he's writing, or he's working from a terminal/interactive Stata session and doesn't want to go back to the do-file to create -tab- results (?)), but it's also worth mentioning that this is all much easier from a do-file where he could use something like:
*******
loc myvars rep78 for
loc myvars2 turn trunk price mpg
foreach v in `myvars' {
foreach m in `myvars2' {
tab `m' `v', col V w nokey miss
}
}
*******
and just manipulate the local myvar lists.
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Mar 7, 2011, at 8:46 PM, Scott Talkington wrote:
> The stuff that stumps me in stata is usually something so simple that it's impossible to find a help file or a faq that deals with it in simple terms.
>
> I want to write a program that obtains a variable name from keyboard input and then executes a series of commands on that variable. This should be pretty simple programming but I can't find a simple description of it.
>
> lets say I want to fill a local variable `x' with one variable name and a local variable `y' with another variable name than then execute the command
>
> .tab `x' `y'
>
> and then at the end of the loop it just stops and waits for the keyboard input again
>
> Isn't there a simple and obvious way to do this? Or is it so obvious that it's never mentioned? It's driving me nuts.
> *
> * 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/