
'define matrix results
matrix(100000,25) results
 scalar i=0

'!c(1) = define variable for beta coefficient 
for !c1=0.008 to 0.1 step 0.01
'!c(2) = define variable for alpha coefficient
	for !c2=0.1 to 0.95 step 0.1
'!c(3) = define variable for theta coefficient 
		for !c3=0.1 to 0.95 step 0.1
'!c(4) = define variable for phi coefficient
			for !c4=0.1 to 1 step 0.1
'!c(5) = define variable for beta1 coefficient
				for !c5=0.1 to 0.95 step 0.1

					'matrix row numbers 
					i=i+1

					'assign starting values to coefficient vector.
					c(1)=!c1
					c(2)=!c2
					c(3)=!c3
					c(4)=!c4
					c(5)=!c5
					
					'record starting values in matrix 
					results(i,1)=!c1
					results(i,2)=!c2
					results(i,3)=!c3
					results(i,4)=!c4
					results(i,5)=!c5

					'set max number of errors
					setmaxerrs 100000
					
					'count errors before estimation
					!old_count = @errorcount
						
					'NLS estimation
					equation nls.ls log(y) = (1/((1-@logit(c(2)))*(1-c(3))-c(5)))*(((1-exp(-c(1)*@trend))*@logit(c(2))*(1-c(3))*log(s))+((1-exp(-c(1)*@trend))*c(5)*log(l))+((1-exp(-c(1)*@trend))*c(4)*log(fi))+((1-exp(-c(1)*@trend))*log(gamma+(1-@logit(c(2)))*c(5)*n))+((1-exp(-c(1)*@trend))*@logit(c(2))*(1-c(3))*log((n+delta)+(c(5)*n)))+((exp(-c(1)*@trend))*log(y(-1))))


						
					'count error after estimation
					!new_count = @errorcount
					
						'if nls estimation error occurred, write 99 in the relevant columns of matrix.
						'goto next simulation value set
						if !new_count > !old_count then
	
							!t=1
							for !x = 6 to 25
									results(i,!x) = 99
									!t=!t	+1
							next
							
						else
						'assign converged values of coefficients in NLS estimation to columns 6 to 10 of matrix
							!z=1
							for !y = 6 to 10	
									'record them to the matrix
									results(i,!y)=nls.@coefs(!z)
									!z=!z+1
							next
						
						'assign std errors of converged coefficients to columns 11 to 15 of matrix
							!z=1
							for !k = 11 to 15	
									'record them to the matrix
									results(i,!k)=nls.@stderrs(!z)
									!z=!z+1
							next

						'assign t-values of converged coefficients to columns 16 to 20 of matrix
							!z=1
							for !k = 16 to 20	
									'record them to the matrix
									results(i,!k)=nls.@tstats(!z)
									!z=!z+1
							next			

						'assign p-values of converged coefficients to columns 21 to 25 of matrix
							!z=1
							for !k = 21 to 25	
									'record them to the matrix
									results(i,!k)=nls.@pval(!z)
									!z=!z+1
							next			


						endif

next
	next
		next
			next
				next


