Hello,
I am writing a program using Stata MP 14.2 that prompts the user for different pieces of information that will eventually populate a dataset of personnel details. For instance, the user will answer questions about which workers attended a weekly meeting, how long that weekly meeting was, when it was held, etc. These answers will be stored as globals and then used to populate new observations in a personnel dataset.
As an example, one part of my code that currently works is question that prompts the user entering in the length of time for weekly meetings. It includes a check (albeit not foolproof, but good enough for my purposes) to make sure the date is entered in the format that I want. If it is not, it prompts the user to enter the date in again.
This post is about another question that I need to ask regarding who was at the meeting -- specifically, how to include a similar check for accuracy in this as I do for the date question above.
The question that the user is prompted with is below:
My goal is to compare the name(s) entered in response to this question and double check if they are spelled right according to my current list of workers. So, if my list of workers is:
and "ron ginny draco" is entered in as a response to the the question about who was not at the meeting, I want the program to recognize that "draco" is not an accepted answer and say something like:
All of the solutions I've explored (counters comparing the number of names that match my $workers global to the number of names in the $whonotmeeting global, using a foreach loop to go through each name in the $whonotmeeting global and compare that to the full string of names in the $workers global) are able to recognize when a name doesn't match the full list of names that I am checking it against, but do not reset the question and name vetting process from the beginning (ie, for a reentering of all names).
Any help is appreciated; happy to clarify the above as needed.
Thanks,
Sarah
I am writing a program using Stata MP 14.2 that prompts the user for different pieces of information that will eventually populate a dataset of personnel details. For instance, the user will answer questions about which workers attended a weekly meeting, how long that weekly meeting was, when it was held, etc. These answers will be stored as globals and then used to populate new observations in a personnel dataset.
As an example, one part of my code that currently works is question that prompts the user entering in the length of time for weekly meetings. It includes a check (albeit not foolproof, but good enough for my purposes) to make sure the date is entered in the format that I want. If it is not, it prompts the user to enter the date in again.
Code:
di "What date was the meeting? Enter it as in the following example: 10 Nov 2016" _request(meetingdate) while regexm("$meetingdate", "^[0-3]?[0-9]+ [A-Z][a-z][a-z] 20[1-2][0-9]$")!=1 { di "Your input is not in the following format: 10 Nov 2016. Please try again" di "What date was the meeting? Enter it as in the following example: 10 Nov 2016" _request(meetingdate) }
The question that the user is prompted with is below:
Code:
di "Who was not at the meeting?", _request(whonotmeeting)
Code:
global workers "harry hermoine ron ginny fred george"
Code:
di "At least one of the names you entered is not correct. Please reenter the list of who did not attend the meeting" di "Who was not at the meeting?", _request(whonotmeeting)
Any help is appreciated; happy to clarify the above as needed.
Thanks,
Sarah
Comment