My Authors
Read all threads
Earlier threads have considered the use of the –recast– option in @Stata graphics. Here's another.
The –twoway function– command in Stata permits nice visualizations of explicit functions y=f(x) over some continuous domain of x-values. E.g.

twoway function y=normal(x), range(-3 3)
This can be helpful in...

— visualizing comparative features of different explicit functions

— visualizing theoretical vs. empirical results (e.g. goodness-of-fit)

— etc.
–twoway function– more or less assumes a continuous domain of x-values. The number of the function's evaluation points can be modified but this doesn't readily handle situations where the x-domain is naturally discrete.
This is where –recast– can help.
A general syntax for integer-valued x is (f(x) is some function Stata recognizes, eg normal(x)):

loc mn=(min x to plot)
loc mx=(max x to plot)
loc pts=`mx'-`mn'+1
tw fun y=f(x), ra(`mn' `mx') n(`pts') recast(scatter) [any options applicable to –twoway scatter– can go here]
For example, to see what a Poisson distribution with parameter lambda=2 looks like, one could use the command:

twoway function y=poissonp(2,x), ra(0 8) xlab(0(1)8) ylab(0(.1).3, ang(360)) xt(y) yt(Prob., orient(hor)) graphr(col(white))

which gives this:
Alternatively,

twoway function y=poissonp(2,x), ra(0 8) n(9) recast(scatter) msym(s) mcol(orange) msi(*2) xlab(0(1)8) ylab(0(.1).3, ang(360)) xt(y) yt(Prob., orient(hor)) graphr(col(white))

gives this:
As an alternative one could, of course, create a dataset that defines x at appropriate points, generate the corresponding y values as f(x), and then –scatter y x–. But why go to all that extra work when –recast– can do the heavy lifting?
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with John Mullahy

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!