/************************************* ex1.do written 10/2007 by Russell Dimond Example from http://ssc.wisc.edu/sscc/pubs/4-26.htm see also mataclass.do and ex2.do **************************************/ clear log using ex1.log,replace mata mata clear /* Example: Loops and Functions */ function x(x0,v0,a,t) { x=x0+v0*t+1/2*a*t^2 return(x) } x0=0,0,0 v0=10,0,0 a=0,0,0 x(x0,v0,a,10) v0=0,0,0 a=0,0,1 x(x0,v0,a,10) x0=0,500 v0=100,0 a=0,-9.8 end clear set obs 1000 gen x=. gen y=. mata r=0 st_view(r,.,.) for(i=1; i<=1000; i++) { r[i,.]=x(x0,v0,a,i/100) } end scatter y x log close