*! version 1.0.0 Stephen P. Jenkins, Dec 1997
*! Fitting of Dagum distribution by ML
*! Called by dagumfit.ado

program define dagum_ll

version 4.0

	tempvar lnx lnt

	local c "`1'"  /* starting value vector on input */
	local f "`2'"  /* scalar to contain function value */
	local p1 = `c'[1,1]
	local p2 = `c'[1,2]
	local p3 = `c'[1,3]

	tempname b d h   /* beta delta lambda */

	scalar `b' = exp(`p1')
	scalar `d' = exp(`p2')
	scalar `h' = exp(`p3') + 1

	quietly  {

	summ $_mlwgt
	local sum0 = _result(3)*_result(1)

	gen double `lnx' = $S_mlwgt * ln($S_mldepn)
	summ `lnx'
	local sum1 = _result(3)*_result(1)

	gen double `lnt' = $S_mlwgt*ln(1+`h'*($S_mldepn^-`d'))
	summ `lnt'
	local sum2 = _result(3)*_result(1)

	scalar `f' = `sum0' * ln(`b'*`d'*`h')  /*
                 */   - (`d'+1)*`sum1' - (`b'+1)*`sum2'

  	}

end