Enhancing Stata Learning with Prompt-Based Programming

 
P
r
o
m
p
t
-
b
a
s
e
d
 
p
r
o
g
r
a
m
m
i
n
g
:
 
 
Zhenghao (Vincent) Jin, MHS, Abimereki Muzaale, MD MPH
Johns Hopkins University
 
 
E
a
s
i
n
g
 
t
h
e
 
S
t
a
t
a
 
l
e
a
r
n
i
n
g
 
c
u
r
v
e
 
Program name
 
Required syntax
 
Optional Syntax
 
Available options
 
Traditional Syntax Based
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
Difficulties in achieving research
goals reported due to lacking
skills in operating Stata
programs
 
Syntax Based
 
Syntax Based
 
Time for 50% of students succeed
on automating table 1 production
or regression analysis
 
Syntax Based
 
Prompt Based
 
Time for 50% of students succeed
on automating table 1 production
or regression analysis
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
P
r
o
m
p
t
 
B
a
s
e
d
 
P
r
o
g
r
a
m
m
i
n
g
 
Integrating the user input into program executions.
The function:
_request()
 
option under Stata’s display command
display “Information to request user input”,
_request(macro_name)
 
P
r
o
m
p
t
 
B
a
s
e
d
 
P
r
o
g
r
a
m
m
i
n
g
 
Integrating the user input into program executions.
The function:
_request()
 
option under Stata’s display command
display “Information to request user input”,
_request(macro_name)
 
P
r
o
m
p
t
 
B
a
s
e
d
 
P
r
o
g
r
a
m
m
i
n
g
 
Integrating the user input into program executions.
The function:
_request()
 
option under Stata’s display command
display “Information to request user input”,
_request(macro_name)
 
Request option tells Stata to throw out a
prompt here
 
 
Displaying the string (prompt question)
Pause the program and wait for input
 
 
User enter input from the Command window
and hit enter
 
 
Information is taken in and prompt is
completed
 
Information will be stored in a global macro
with a name specified by the code
 
U
t
i
l
i
z
i
n
g
 
U
s
e
r
 
I
n
p
u
t
 
The user input can be modified and used for
different purposes:
Confirmation
Parameter intake
 
C
o
n
f
i
r
m
a
t
i
o
n
-
p
r
o
g
r
a
m
 
c
h
e
c
k
 
p
o
i
n
t
s
 
P
r
o
m
p
t
s
 
c
a
n
 
s
e
t
 
c
r
i
t
i
c
a
l
 
p
o
i
n
t
s
 
f
o
r
 
u
s
e
r
 
t
o
 
c
h
e
c
k
 
p
r
o
g
r
a
m
s
e
t
t
i
n
g
s
 
b
e
f
o
r
e
 
a
c
t
u
a
l
 
e
x
e
c
u
t
i
o
n
s
 
Desired parameter values:
ys – 1988 ye – 2017 ds - 2
 
But we won’t know and find
the error until at least 400
seconds after
 
This is the error!
 
This is the confirmation prompt
 
There is an error, so entering N to deny proceeding
 
This is a check point before
actual execution
 
With check-points from
prompt, it only takes 13s!
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
U
t
i
l
i
z
i
n
g
 
U
s
e
r
 
I
n
p
u
t
 
The user input can be modified and used for
different purposes:
Confirmation
Parameter intake
 
P
a
r
a
m
e
t
e
r
 
I
n
t
a
k
e
 
 
c
l
e
a
n
e
r
 
f
a
s
h
i
o
n
 
P
r
o
m
p
t
s
 
c
a
n
 
t
a
k
e
 
i
n
 
p
a
r
a
m
e
t
e
r
s
 
i
n
 
c
l
e
a
n
e
r
 
f
a
s
h
i
o
n
.
Avoid potential error in constructing lists
Easy to understand and follow
 
Include everything  at
program call –
long lists leave spaces for
human errors
 
No more long lists, less errors!
 
Traditional Syntax
 
Prompt Based
 
Transforming long option lists to
prompts one-at-a-time
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
Helpful statistics to help
user recall
 
Can check input after intake
 
Only 1 or 2, 3 is NOT valid
 
Modification without
termination
 
B
a
c
k
g
r
o
u
n
d
 
a
n
d
 
H
y
p
o
t
h
e
s
i
s
 
P
r
o
m
p
t
 
b
a
s
e
d
 
Multiple parameter intakes
Mandatory, self-explanatory intake
Check points and Modifications
without termination
 
T
r
a
d
i
t
i
o
n
a
l
 
s
y
n
t
a
x
 
One time intake for parameters
Needs to study the syntax
Hard to identify/fix errors
 
T
H
A
N
K
 
Y
O
U
!
 
I
s
s
u
e
s
 
a
n
d
 
L
i
m
i
t
a
t
i
o
n
 
45
 
P
r
o
m
p
t
s
 
a
r
e
 
m
a
n
d
a
t
o
r
y
hard to automate
hard to integrate into other program or codes
H
a
r
d
 
t
o
 
c
o
m
p
i
l
e
Multiple inputs require for one test
 
I
s
s
u
e
s
 
a
n
d
 
L
i
m
i
t
a
t
i
o
n
 
46
 
P
r
o
m
p
t
s
 
a
r
e
 
m
a
n
d
a
t
o
r
y
hard to automate
hard to integrate into other program or codes
H
a
r
d
 
t
o
 
c
o
m
p
i
l
e
Multiple inputs require for one test
 
P
o
s
s
i
b
l
e
 
S
o
l
u
t
i
o
n
 
F
R
O
M
 
T
H
I
S
:
 
program define test
    noi di “This is a request”, _request(content)
    noi di “Your input is: ${content}”
end
 
 
 
P
r
e
s
p
e
c
i
f
y
 
t
h
e
 
g
l
o
b
a
l
 
m
a
c
r
o
 
r
e
q
u
e
s
t
e
d
 
t
o
 
b
y
p
a
s
s
 
t
h
e
 
r
e
q
u
e
s
t
 
P
o
s
s
i
b
l
e
 
S
o
l
u
t
i
o
n
 
F
R
O
M
 
T
H
I
S
:
 
program define test
    noi di “This is a request”, _request
(content)
    noi di “Your input is: 
${content}
end
 
 
 
P
r
e
s
p
e
c
i
f
y
 
t
h
e
 
g
l
o
b
a
l
 
m
a
c
r
o
 
r
e
q
u
e
s
t
e
d
 
t
o
 
b
y
p
a
s
s
 
t
h
e
 
r
e
q
u
e
s
t
 
P
o
s
s
i
b
l
e
 
S
o
l
u
t
i
o
n
 
TO THIS:
global 
content
 : di “Example input.”
program define test
    syntax, 
[pro]
    
if (“`pro’” != “pro”) {
        noi di “This is a request”, _request(
content
)
    
}
    noi di “Your input is: 
${content}
end
 
L
e
s
s
o
n
 
L
e
a
r
n
e
d
 
A
l
l
 
a
p
p
r
o
a
c
h
e
s
 
a
r
e
 
u
s
e
f
u
l
 
f
o
r
 
p
r
o
g
r
a
m
s
.
T
h
e
 
k
e
y
 
i
s
s
u
e
 
i
s
 
t
o
 
i
d
e
n
t
i
f
y
 
t
a
r
g
e
t
i
n
g
 
u
s
e
r
 
p
o
p
u
l
a
t
i
o
n
more user focused and acts independent
prompt based may be better
Collaborating/integrating with other program/complicated scripts
syntax approach may be better
I
t
 
i
s
 
a
l
w
a
y
s
 
i
m
p
o
r
t
a
n
t
 
t
o
 
t
h
i
n
k
 
a
b
o
u
t
 
t
h
e
 
a
c
t
u
a
l
 
g
o
a
l
 
o
f
 
t
h
e
p
r
o
g
r
a
m
how it will be used? where it will be placed?
 
 
L
e
s
s
o
n
 
L
e
a
r
n
e
d
 
A
l
l
 
a
p
p
r
o
a
c
h
e
s
 
a
r
e
 
u
s
e
f
u
l
 
f
o
r
 
p
r
o
g
r
a
m
s
.
T
h
e
 
k
e
y
 
i
s
s
u
e
 
i
s
 
t
o
 
i
d
e
n
t
i
f
y
 
t
a
r
g
e
t
i
n
g
 
u
s
e
r
 
p
o
p
u
l
a
t
i
o
n
more user focused and acts independent
prompt based may be better
Collaborating/integrating with other program/complicated scripts
syntax approach may be better
I
t
 
i
s
 
a
l
w
a
y
s
 
i
m
p
o
r
t
a
n
t
 
t
o
 
t
h
i
n
k
 
a
b
o
u
t
 
t
h
e
 
a
c
t
u
a
l
 
g
o
a
l
 
o
f
 
t
h
e
p
r
o
g
r
a
m
how it will be used? where it will be placed?
 
 
L
e
s
s
o
n
 
L
e
a
r
n
e
d
 
A
l
l
 
a
p
p
r
o
a
c
h
e
s
 
a
r
e
 
u
s
e
f
u
l
 
f
o
r
 
p
r
o
g
r
a
m
s
.
T
h
e
 
k
e
y
 
i
s
s
u
e
 
i
s
 
t
o
 
i
d
e
n
t
i
f
y
 
t
a
r
g
e
t
i
n
g
 
u
s
e
r
 
p
o
p
u
l
a
t
i
o
n
more user focused and acts independent
prompt based may be better
Collaborating/integrating with other program/complicated scripts
syntax approach may be better
I
t
 
i
s
 
a
l
w
a
y
s
 
i
m
p
o
r
t
a
n
t
 
t
o
 
t
h
i
n
k
 
a
b
o
u
t
 
t
h
e
 
a
c
t
u
a
l
 
g
o
a
l
 
o
f
 
t
h
e
p
r
o
g
r
a
m
how it will be used? where it will be placed?
 
 
L
e
s
s
o
n
 
L
e
a
r
n
e
d
 
A
l
l
 
a
p
p
r
o
a
c
h
e
s
 
a
r
e
 
u
s
e
f
u
l
 
f
o
r
 
p
r
o
g
r
a
m
s
.
T
h
e
 
k
e
y
 
i
s
s
u
e
 
i
s
 
t
o
 
i
d
e
n
t
i
f
y
 
t
a
r
g
e
t
i
n
g
 
u
s
e
r
 
p
o
p
u
l
a
t
i
o
n
more user focused and acts independent
prompt based may be better
Collaborating/integrating with other program/complicated scripts
syntax approach may be better
I
t
 
i
s
 
a
l
w
a
y
s
 
i
m
p
o
r
t
a
n
t
 
t
o
 
t
h
i
n
k
 
a
b
o
u
t
 
t
h
e
 
a
c
t
u
a
l
 
g
o
a
l
 
o
f
 
t
h
e
p
r
o
g
r
a
m
how it will be used? where it will be placed?
 
 
L
e
s
s
o
n
 
L
e
a
r
n
e
d
 
A
l
l
 
a
p
p
r
o
a
c
h
e
s
 
a
r
e
 
u
s
e
f
u
l
 
f
o
r
 
p
r
o
g
r
a
m
s
.
T
h
e
 
k
e
y
 
i
s
s
u
e
 
i
s
 
t
o
 
i
d
e
n
t
i
f
y
 
t
a
r
g
e
t
i
n
g
 
u
s
e
r
 
p
o
p
u
l
a
t
i
o
n
more user focused and acts independent
prompt based may be better
Collaborating/integrating with other program/complicated scripts
syntax approach may be better
I
t
 
i
s
 
a
l
w
a
y
s
 
i
m
p
o
r
t
a
n
t
 
t
o
 
t
h
i
n
k
 
a
b
o
u
t
 
t
h
e
 
a
c
t
u
a
l
 
g
o
a
l
 
o
f
 
t
h
e
p
r
o
g
r
a
m
how it will be used? where it will be placed?
 
Slide Note

Reduce the credit part and proceed with only the title – Use we to shortening the scripts all the time

Embed
Share

Explore the benefits of prompt-based programming in easing the learning curve of Stata software. This innovative approach simplifies syntax, reduces errors, and enhances efficiency for data analysis tasks. By comparing prompt-based versus traditional syntax methods, researchers can improve their skills and achieve research goals more effectively.

  • Stata software
  • Data analysis
  • Prompt-based programming
  • Syntax simplification
  • Research efficiency

Uploaded on Sep 19, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Prompt-based programming: Easing the Stata learning curve Zhenghao (Vincent) Jin, MHS, Abimereki Muzaale, MD MPH Johns Hopkins University

  2. Program name

  3. Required syntax

  4. Optional Syntax

  5. Available options

  6. Traditional Syntax Based

  7. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  8. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  9. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  10. Syntax Based Difficulties in achieving research goals reported due to lacking skills in operating Stata programs

  11. Syntax Based Time for 50% of students succeed on automating table 1 production or regression analysis

  12. Prompt Based Syntax Based Time for 50% of students succeed on automating table 1 production or regression analysis

  13. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  14. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  15. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  16. Prompt Based Programming Integrating the user input into program executions. The function: _request() option under Stata s display command display Information to request user input , _request(macro_name)

  17. Prompt Based Programming Integrating the user input into program executions. The function: _request() option under Stata s display command display Information to request user input , _request(macro_name)

  18. Prompt Based Programming Integrating the user input into program executions. The function: _request() option under Stata s display command display Information to request user input , _request(macro_name)

  19. Request option tells Stata to throw out a prompt here

  20. Displaying the string (prompt question) Pause the program and wait for input

  21. User enter input from the Command window and hit enter

  22. Information is taken in and prompt is completed

  23. Information will be stored in a global macro with a name specified by the code

  24. Utilizing User Input The user input can be modified and used for different purposes: Confirmation Parameter intake

  25. Confirmation-program check points Prompts can set critical points for user to check program settings before actual executions

  26. Desired parameter values: ys 1988 ye 2017 ds - 2

  27. This is the error! But we won t know and find the error until at least 400 seconds after

  28. This is a check point before actual execution This is the confirmation prompt There is an error, so entering N to deny proceeding

  29. With check-points from prompt, it only takes 13s!

  30. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  31. Utilizing User Input The user input can be modified and used for different purposes: Confirmation Parameter intake

  32. Parameter Intake cleaner fashion Prompts can take in parameters in cleaner fashion. Avoid potential error in constructing lists Easy to understand and follow

  33. Include everything at program call long lists leave spaces for human errors Traditional Syntax Prompt Based No more long lists, less errors!

  34. Transforming long option lists to prompts one-at-a-time

  35. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  36. Helpful statistics to help user recall

  37. Only 1 or 2, 3 is NOT valid Can check input after intake

  38. Modification without termination

  39. Background and Hypothesis Prompt based Traditional syntax Multiple parameter intakes One time intake for parameters Mandatory, self-explanatory intake Needs to study the syntax Check points and Modifications Hard to identify/fix errors without termination

  40. THANK YOU!

  41. Issues and Limitation Prompts are mandatory hard to automate hard to integrate into other program or codes Hard to compile Multiple inputs require for one test 45

  42. Issues and Limitation Prompts are mandatory hard to automate hard to integrate into other program or codes Hard to compile Multiple inputs require for one test 46

  43. Possible Solution Prespecify the global macro requested to bypass the request FROM THIS: program define test noi di This is a request , _request(content) noi di Your input is: ${content} end

  44. Possible Solution Prespecify the global macro requested to bypass the request FROM THIS: program define test noi di This is a request , _request(content) noi di Your input is: ${content} end

  45. Possible Solution TO THIS: global content : di Example input. program define test syntax, [pro] if ( `pro != pro ) { noi di This is a request , _request(content) } noi di Your input is: ${content} end

  46. Lesson Learned All approaches are useful for programs. The key issue is to identify targeting user population more user focused and acts independent prompt based may be better Collaborating/integrating with other program/complicated scripts syntax approach may be better It is always important to think about the actual goal of the program how it will be used? where it will be placed?

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#