, 9 tweets, 2 min read
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)

— 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.

Keep Current with John Mullahy

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

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!

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