Starting with a blank STATA session, you can set the number of observations and declare the file to be a time series as follows. If you want to create a file with 100 observations, use the commands:
.set obs 100
.gen t=_n
.tsset t
Before generating random numbers you can set the “seed” for the random number generator. The command takes the form
.set seed 149834500
where in this example the “seed” is the number . If you don’t specify a seed the default is 123456789 when Stata is started up.
To simulate a Gaussian white noise process use the command
.gen e=rnormal()
This generates a variable “e” filled with random normal N(0,1) shocks.
To create a moving average process 𝑦' = 𝜀' + 0.3𝜀'45, use the command
.gen y=e+0.3*L.e
This takes the variable “e” previously defined, creates the lagged value and creates a moving average process with coefficient 0.3.
To create the autoregressive process 𝑦' = 0.5𝑦'45 + 𝑒' with y1 = 0, use the following two- command sequence:
.gen y=0
.replace y=0.5*L.y+e if t>1
where “e” and “t” are as previously defined.