*! estimadip v1.0 JavierMarquez 22dic2009
program define estimadip
	version 10
	local prog tlogit estsimp
	foreach p of local prog {
		capt which `p'
		if _rc {
		    di as error "-{bf:estimadip}- requires {it:Clarify} ; " _c
		    di as error `"click {stata "net install clarify,from(http://gking.harvard.edu/clarify)" :here}"' _c
		    di as error " for installation or type " _c
		    di as error `"{stata "net from http://gking.harvard.edu/clarify/"}"'
		    error 499
		}
    	}
	syntax anything(name=eqlist id="equation list") [if] [in], 		///
		Base(varname) [Tstub(string) SIMSTub(string) 				///
		Sims(integer 1000)]
	tokenize `eqlist',  p("()")
		if "`1'" != "(" {
			di as error "equation list requires parentheses"
			error 499
		}
		local j = 0
		local i = 0
		while "``++i''" != "" {
			if "``i''" != "(" & "``i''" != ")" {
				local eq`++j' ``i''
				confirm numeric variable `eq`j''
				gettoken dep`j' indep`j' : eq`j'
	       	}
		}
		local n_eq = `j'
	di
	di "{txt}{hline 78}"
	di as text "Executing {bf:estimadip}"
	di "{txt}{hline 78}"
	di
	di as text 														///
		"{bf:estimadip} will generate the following variables: " _c
	if "`tstub'" == "" {
		local tstub _t
	}
	if "`simstub'" == "" {
		local simstub _beta
	}
	forvalues i = 1/`n_eq' {
		local tvars `tvars' `dep`i'' `tstub'`dep`i''
		local neweqlist `neweqlist'  (`tstub'`dep`i'' `indep`i'')
		di as result "`tstub'`dep`i'' " _c
	}
	di
	tlogit `tvars', base(`base')
	di
	di as text "Invoking {bf:estsimp} ..."
	di as text "Remember coefficients are expressed as log ratios"
	estsimp sureg `neweqlist' `if' `in', sims(`sims') genname(`simstub')
end