Hello,
When requesting user input (i.e., console input) during the execution of a do file, I would like Stata to wait up to X seconds for a user input (e.g., any character). If it receives a character input within X seconds, I would like the do file to continue execution, otherwise, I would like it to continue and use a default value for the missing entry.
How can I accomplish this? Here is my failed attempt (with X=5):
local y = clock("`c(current_time)'", "hms")
local cmd ""
local duration 0
while ( strlen("`cmd'")==0 & `duration'<5000 ) {
if ( strlen("`cmd'")==0 ) {
I assume this fails to function as I intended because the while loop cannot move past the display line until an entry is received from the user.
I am starting to think that display _request() cannot be used in this way. I also do not see how to use a dialog box for this, but I have not read the documentation for more than 10 minutes.
I would prefer not to use user-written commands, only those that come with my version of Stata. I am using Stata/MP version 17.0.
When requesting user input (i.e., console input) during the execution of a do file, I would like Stata to wait up to X seconds for a user input (e.g., any character). If it receives a character input within X seconds, I would like the do file to continue execution, otherwise, I would like it to continue and use a default value for the missing entry.
How can I accomplish this? Here is my failed attempt (with X=5):
local y = clock("`c(current_time)'", "hms")
local cmd ""
local duration 0
while ( strlen("`cmd'")==0 & `duration'<5000 ) {
local duration = clock("`c(current_time)'", "hms") - `y'}
display "enter command: " _request(cmd)
local cmd "$cmd"
if ( strlen("`cmd'")==0 ) {
local cmd "default_value"}
I assume this fails to function as I intended because the while loop cannot move past the display line until an entry is received from the user.
I am starting to think that display _request() cannot be used in this way. I also do not see how to use a dialog box for this, but I have not read the documentation for more than 10 minutes.
I would prefer not to use user-written commands, only those that come with my version of Stata. I am using Stata/MP version 17.0.
Comment