# create an empty data set with 200 observations nulldata 200 # fix a random seed for replicability set seed 1707138404 # generate a Gamma random variable x with shape k = 3 and scale theta = 2 series x = randgen(G, 3, 2) # initialize estimates via sample moments m = mean(x) theta = var(x) / m k = m / theta mle logl = check ? k*ln(y) - lngamma(k) - ln(x) - y : NA series y = x/theta check = k > 0 && theta > 0 params k theta end mle