*! qscope_example1.ado by Shunjie Tu and Mead Over, Version 1.5 4Jan2017
*! Companion program to be executed by the help file: qscope.sthlp
program qscope_example1
    preserve
		set more off
		capture prog drop qscope
		capture prog drop flexmake

		di _n as inp `". sysuse qscope_costdata, clear"'
		sysuse qscope_costdata, clear

		di _n as inp ". *** Set the missing price variable to equal Other expenditure (q_oth=1)***"
		di _n as inp ". gen p_Oth = costOth"
		gen p_Oth = costOth
		di _n as inp `". lab var p_Oth "Arbitrary price for the -Other- input""'
		lab var p_Oth "Arbitrary price for the -Other- input"

		di _n as inp `". describe"'
		describe

		di _n as inp `". summarize"'
		summarize

		di _n as inp ". *** transform data ***"
		di _n as inp ". *	Use the program {help flexmake} to construct the logarithmic transformations"
		di _n as inp ". *	and to create global macros which facilitate estimation."
		di _n as inp ". flexmake , outputs(artpy hivpy) prices(P_DP P_IP ptest P_OI pnut p_Oth) incosts(cost*) innames(DP IP test OI nut Oth) ln half global"
		flexmake , outputs(artpy hivpy) prices(P_DP P_IP ptest P_OI pnut p_Oth) incosts(cost*) innames(DP IP test OI nut Oth) ln half global

		di _n as inp ". ***	Specify the regressors ***"
		di _n as inp ". *	Having executed {help flexmake} with the {cmd:global} option,"
		di _n as inp ". *	the regression command can be assembled from those global macros."
		di _n as inp ". global outputvariables \${ownoutputs} \${ownoutputs2} \${crossoutputs} "
		global outputvariables ${ownoutputs} ${ownoutputs2} ${crossoutputs}

		di _n as inp ". global pricevariables  \${ownprices} \${ownprices2} \${crossprices} \${outputsxprices} "
		global pricevariables  ${ownprices} ${ownprices2} ${crossprices} ${outputsxprices}

		di _n as inp ". global othervars i.nation "
		global othervars i.nation

		di _n as inp ". *** Estimates of QSCOPE when cost function is estimated by OLS ***"
		di _n as inp ". reg \${depvar} \${outputvariables} \${pricevariables} \${othervars}"
		reg ${depvar} ${outputvariables} ${pricevariables} ${othervars}

		di _n as inp ". *** qscope ***"
		di _n as inp ". qscope, outputs(\${outputs}) epsilon(0.0001 0.001 0.01 0.1) chain(ln)"
		qscope, outputs(${outputs}) epsilon(0.0001 0.001 0.01 0.1) chain(ln)

		di _n as inp ". qscope, outputs(\${outputs}) epsilon(0.0001 0.001 0.01 0.1) chain(ln) median"
		qscope, outputs(${outputs}) epsilon(0.0001 0.001 0.01 0.1) chain(ln) median

	restore
end
*	Version 1.0 by Shunjie Tu  13Jul2016
*	Version 1.1 9Sep2016 Subsequent revisions by Mead Over
*	Version 1.2 14Sep2016 Add escape character prior to -$-'s so that globals are visible
*		Add describe and summarize commands and additional comments.
*	Version 1.3 31Oct2016 Add the innames option and the p_Oth price to flexmake
*	Version 1.4 20Dec2016 Set the quantity rather than the price of Other to 1.0
*	Version 1.5 4Jan2017 Estimate qscope for four values of epsilon at once
*	Version 1.6 23Jan2017 Estimate qscope for four values of epsilon at once