Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Prompt user of ado file for input & output file names & path

From   Partho Sarkar <>
Subject   st: Re: Prompt user of ado file for input & output file names & path
Date   Thu, 7 Jul 2011 14:52:09 +0530

Thank you so much, Eric!  And sorry for the late response-I had given
up hope of getting a more explicit answer here, and looked it up quite
laboriously elsewhere.  I had discovered about the -display,
_request(), and also -db use for the browser option. But your answer
is nonetheless very useful.

Nick is of course right to suggest that one should first search
through the help files, manuals etc, and I usually do that quite a
bit.  But I am having to pick up Stata on the go, as it were, within a
very tight corporate work-schedule in mid-career, hence the naivete of
some of my questions. (I suppose the same goes for many of the
"newbies" here!)

Thank you again for taking the time to give a detailed and very
helpful answer.   And in case you or someone would care to help with a
few more basic queries, here are a few wrinkles I am struggling with
right now (comments in do file style)

1.  *An attempt with  _request:
. noi di " ENTER SOURCE FILE NAME --> "  _request(answer)
di "File name =$answer "

/*But what if what if the user inadvertently hits the <enter> key w/o
entering any name? to take care of that,I tried the next 3 lines of
code, the idea being to repeatedly prompt the user till he does enter
a valid name:*/

if "${answer}" == "" {
di " PLEASE ENTER SOURCE FILE NAME --> "  _request(answer

/* but this does nor work- it produces the following:
invalid syntax

2.  Further, suppose I want to prompt the user for a csv file to use
with the insheet command.  I can use

db insheet

but this allows various ascii file formats, and the rest of my ado
file will only work if the file is csv, and with comma (not tab!)
separators.  How to ensure this? [A successful choice via the window
menu would produce a result as below:
insheet using "C:\Users\indicus-laptop\Desktop\prices.csv", comma]

Thanks again

Eric A. Booth wrote [4 Jul 2011 17:19:10 +0000]:<>
As Nick suggested, -dialog- boxes are what you want (especially to
allow users to navigate folders); however,  I also like to use
-display, request()- (see -help display-) and thought others may find
it useful:

"'  _request(ans)
	**puts path in global macro $ans
**echo that back to the user:
window stopbox note `"PATH ENTERS AS :  $ans"'
di `"PATH ENTERED AS:  $ans"'
- Eric
*   For searches and help try:

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