If you are downloading this SHAZAM code for use on your own computer, select "File", then "Save As...", and save on your own diskette (a:) or your own hard drive (c:\) using the same filename e143sh2.sha.
IMPORTANT: you must then use an editor (like TED) to delete all of the HTML code from the top and the bottom of the file, leaving only the SHAZAM code. The line which reads "* SHAZAM code (e143sh2.sha) downloaded from UCLA Econ 143 (CAMERON) WebSite" should be the first line of your edited program file. Save theedited program as plotdist.sha
* SHAZAM code downloaded from UCLA Econ 143 (CAMERON) WebSite:
* HTML file called e143sh2.htm, and should have
* been downloaded as plotdist.sha
set nocolor
* PLOTDIST.SHA - This program contains SHAZAM procedures to create data
* that will let you plot
* a.) generic normal probability density functions and cumulative
* density function with arbitrary values for the mean (mu) and the
* standard deviation (sig), plus
* b.) t-distribution probability density functions with mean mu=0 and
* standard deviation sig=1, but with user-specified degrees of
* freedom (df). NOTE: df must be an integer.
* c.) F-distribution probability density functions with numerator degrees
* of freedom, n1, and denominator degrees of freedom, n2.
* NOTE: n1 and n2 must be integers.
* d.) chi-squared distribution probability density functions with degrees
* of freedom, k. NOTE: k must be an integer.
* INSTRUCTIONS: get into SHAZAM and enter file 5 n:plotdist.sha
* Decide which distribution you want to look at
* IF NORMAL, enter commands to set the values you want to use for the
* mean and the standard deviation with the commands (e.g.):
* gen1 mu=10
* gen1 sig=3.5
* If you want the procedure to scale the range of the distribution
* automatically, this is all you need. If you want to set the range
* yourself, you need to enter the following additional commands:
* gen1 scale=0
* gen1 minn=2
* gen1 maxn=25
* were the values of minn and maxn are chosen by the user.
* Now execute the procedure that takes these values and creates the
* corresponding distribution by entering the command:
* exec ndistn
* After this is completed, you will have the corresponding normal
* probability density function in the variable normpdf, the cumulative
* probability density function in the variable normcdf, and the normal
* variable will reside in the variable x.
* You can plot the pdf or the cdf using commands such as:
* plot normpdf x / gnu line ( or try ega instead of gnu )
* plot normcdf x / gnu line ( or try ega instead of gnu )
* >>>the default specification is N(0,1)
* IF T-DISTRIBUTION, the distribution is automatically standardized to have
* a mean of zero and a standard deviation of one. All you need to select
* is a value for the degrees of freedom, df:
* gen1 df=24
* Then execute the procedure with the command
* exec tdistn
* Then plot the results with a command such as:
* plot tpdf t / gnu line ( or try ega instead of gnu )
* >>>the default specification is t(30)
* IF F-DISTRIBUTION, you need to select both numerator and denominator
* degrees of freedom to characterize the distribution:
* gen1 n1=6
* gen1 n2=20
* Then execute the procedure with the command
* exec fdistn
* Then you can plot the results with a command such as:
* plot fpdf f / gnu line ( or try ega instead of gnu )
* If you wish to change the domain of the distribution, specify the largest
* value you want displayed by using the command:
* gen1 maxf=8 (for example; default is upper limit of 5)
* >>>the default specification is F(4,40)
* IF CHI-SQUARED DISTRIBUTION, you need to specify the degrees of
* freedom, k
* gen1 k=3
* Then execute the procedure with the command
* exec chidistn
* Then you can plot the results with a command such as:
* plot chipdf chi / gnu line ( or try ega instead of gnu )
* You can change the domain of the distribution by specifying the largest
* value you want displayed by using the command:
* gen1 maxchi=8 (for example; default is upper limit of 15)
* >>>the default specification is chi-squared(4)
********************* BEGINNING OF PROGRAM ********************************
sample 1 100
set nowarn
* changing these will change the domain of the distribution to be displayed
gen1 scale=1
gen1 maxf=0
gen1 maxchi=0
gen1 minn=-10
gen1 maxn=20
* default distributional parameters
* normal distribution
gen1 mu=0
gen1 sig=1
* t-distribution
gen1 df=30
* F-distribution
gen1 n1=4
gen1 n2=40
* chi-squared distribution
gen1 k=4
*===============================================================
* NORMAL DISTRIBUTION
* - you may alter mean (mu) and standard deviation (sig) values
*===============================================================
proc ndistn
if(scale.eq.0) rangeb=minn
if(scale.ne.0) rangeb=mu-4*sig
if(scale.eq.0) ranget=maxn
if(scale.ne.0) ranget=mu+4*sig
gen1 range=ranget-rangeb
genr x=(time(0)*range/100)+rangeb
* x now varies roughly between mu-4*sig and mu+4sig
genr normpdf= (1/(sqrt(2*3.14159)*sig)) * exp(-.5*((x-mu)/sig)*((x-mu)/sig))
genr xstd=(x-mu)/sig
genr normcdf= ncdf(xstd)
procend
*===============================================================
* t-DISTRIBUTION
* - you may alter the degrees of freedom (df)
*===============================================================
proc tdistn
genr t=(time(0)*8/100)-4
gen1 gam1=exp(lgam((df+1)/2))
gen1 gam2=exp(lgam(df/2))
gen1 power=-(df+1)/2
genr tpdf= gam1 * ( (1+(t*t/df))**(power) ) &
/ ( sqrt(3.14159*df) * gam2)
* now you might want to re-name the variable tpdf20 if df=20, for example
* with a command like
* genr tpdf20=tpdf
procend
*===============================================================
* F-DISTRIBUTION
* - you may alter numerator (n1) and denominator (n2) degrees of freedom
* - you may also change the domain (0 - domain) of the plot
*===============================================================
gen1 domain=5
proc fdistn
* domain is domain of the distribution (0,domain)
gen1 gama=exp( lgam( (n1+n2)/2 ) )
gen1 ex1=n1/2
gen1 ex2=n2/2
gen1 ex3=(n1-2)/2
gen1 gamb=exp( lgam(n1/2) )
gen1 gamc=exp( lgam(n2/2) )
gen1 ex4=(n1+n2)/2
if(maxf.ne.0) domain=maxf
genr f=time(0)* domain/100
genr fpdf= gama * (n1**ex1) * (n2**ex2) * (f**ex3) / &
( gamb*gamc* ( ((n1*f)+n2) **ex4 ) )
procend
*===============================================================
* CHI-SQUARED DISTRIBUTION
* - you may change the degrees of freedom (k)
* - you may also change the domain (0 - domainc)
*===============================================================
gen1 domainc=15
proc chidistn
gen1 gamd=exp( lgam(k/2) )
gen1 exp5=(k-2)/2
gen1 exp6=k/2
if(maxchi.ne.0) domainc=maxchi
genr chi=time(0)*domainc/100
genr chipdf= (chi**exp5) * exp(-chi/2) / ( (2**exp6) * gamd )
procend
*===============================================================
| COURSE OUTLINE | LECTURE OUTLINES | PROBLEM SETS | PROBLEM SOLUTIONS |
| COMPUTER LABS | SHAZAM EXAMPLES | DATA SETS | ONLINE QUIZZES |