/*--------------------------- 16Mar2010 - version 2.0 Curve Estimation Author: Liu Wei, The School of Sociology and Population Studies, Renmin University of China E-mail: rucwz-stata@yahoo.cn ---------------------------*/ capture prog drop curvefit prog define curvefit, sortpreserve version 10.0 syntax varlist(numeric max=2) [if] [in], Function(string) [Nograph Initial(string) Count(integer 4)] marksample touse tokenize `varlist' qui sort `2' qui est clear qui cap drop yhat* local fit_num=0 local notfit_num=0 local notfit="" qui { if regexm("`function'","1") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} + ({b1} * (`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} + ({b1} * (`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Linear gen yhat_1=_coef[/b0]+(_coef[/b1]*(`2')) label var yhat_1 "Linear Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Linear " local notfit_num=`notfit_num'+1 } } if regexm("`function'","2") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} + ({b1} * ln((`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} + ({b1} * ln((`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Logarithmic gen yhat_2=_coef[/b0]+(_coef[/b1]*ln((`2'))) label var yhat_2 "Logarithmic Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Logarithmic " local notfit_num=`notfit_num'+1 } } if regexm("`function'","3") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} + ({b1} / (`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} + ({b1} / (`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Inverse gen yhat_3=_coef[/b0]+(_coef[/b1]/(`2')) label var yhat_3 "Inverse Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Inverse " local notfit_num=`notfit_num'+1 } } if regexm("`function'","4") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} + ({b1} * (`2')) + ({b2} * (`2')^2)) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} + ({b1} * (`2')) + ({b2} * (`2')^2)) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Quadratic gen yhat_4=_coef[/b0]+(_coef[/b1]*(`2'))+(_coef[/b2]*(`2')^2) label var yhat_4 "Quadratic Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Quadratic " local notfit_num=`notfit_num'+1 } } if regexm("`function'","5") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} + ({b1} * (`2')) + ({b2} * (`2')^2) + ({b3} * (`2')^3)) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} + ({b1} * (`2')) + ({b2} * (`2')^2) + ({b3} * (`2')^3)) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Cubic gen yhat_5=_coef[/b0]+(_coef[/b1]*(`2'))+(_coef[/b2]*(`2')^2)+(_coef[/b3]*(`2')^3) label var yhat_5 "Cubic Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Cubic " local notfit_num=`notfit_num'+1 } } if regexm("`function'","6") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * ((`2')^{b1})) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * ((`2')^{b1})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Power gen yhat_6=_coef[/b0]*((`2')^_coef[/b1]) label var yhat_6 "Power Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Power " local notfit_num=`notfit_num'+1 } } if regexm("`function'","7") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * ({b1}^(`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * ({b1}^(`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Compound gen yhat_7=_coef[/b0]*(_coef[/b1]^(`2')) label var yhat_7 "Compound Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Compound " local notfit_num=`notfit_num'+1 } } if regexm("`function'","8") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= exp({b0} + ({b1}/(`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= exp({b0} + ({b1}/(`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto S_curve gen yhat_8=exp(_coef[/b0]+(_coef[/b1]/(`2'))) label var yhat_8 "S_curve Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"S_curve " local notfit_num=`notfit_num'+1 } } if regexm("`function'","9") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} / (1 + {b1} * exp(-{b2} * (`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} / (1 + {b1} * exp(-{b2} * (`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Logistic gen yhat_9= _coef[/b0] / (1 + _coef[/b1] * exp(-_coef[/b2] * (`2'))) label var yhat_9 "Logistic Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Logistic " local notfit_num=`notfit_num'+1 } } if regexm("`function'","0") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= exp({b0} + ({b1} * (`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= exp({b0} + ({b1} * (`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Growth gen yhat_0 = exp(_coef[/b0]+(_coef[/b1]*(`2'))) label var yhat_0 "Growth Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Growth " local notfit_num=`notfit_num'+1 } } if regexm("`function'","a") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * (exp({b1} * (`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * (exp({b1} * (`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Exponential gen yhat_a=_coef[/b0]*(exp(_coef[/b1]*(`2'))) label var yhat_a "Exponential Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Exponential " local notfit_num=`notfit_num'+1 } } if regexm("`function'","b") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1' = exp({b0} + {b1}/(`2')+{b2} * ln((`2')))) if `touse', variables(`2') nolog } else { cap nl (`1' = exp({b0} + {b1}/(`2')+{b2} * ln((`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Vapor_Pressure gen yhat_b=exp(_coef[/b0] + _coef[/b1]/(`2')+_coef[/b2] * ln((`2'))) label var yhat_b "Vapor Pressure Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Vapor_Pressure " local notfit_num=`notfit_num'+1 } } if regexm("`function'","c") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'=1/ ({b0} + ({b1} * ln((`2'))))) if `touse', variables(`2') nolog } else { cap nl (`1'=1/ ({b0} + ({b1} * ln((`2'))))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto R_Logarithmic gen yhat_c=1/(_coef[/b0]+(_coef[/b1]*ln((`2')))) label var yhat_c "Reciprocal Logarithmic Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"R_Logarithmic " local notfit_num=`notfit_num'+1 } } if regexm("`function'","d") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'={b0} * {b1}^(`2')) if `touse', variables(`2') nolog } else { cap nl (`1'={b0} * {b1}^(`2')) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto M_Power gen yhat_d=_coef[/b0] * _coef[/b1]^(`2') label var yhat_d "Modified Power Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"M_Power " local notfit_num=`notfit_num'+1 } } if regexm("`function'","e") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * ((`2') - {b1})^{b3}) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * ((`2') - {b1})^{b3}) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Shifted_Power gen yhat_e=_coef[/b0] * ((`2') - _coef[/b1])^_coef[/b3] label var yhat_e "Shifted Power Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Shifted_Power " local notfit_num=`notfit_num'+1 } } if regexm("`function'","f") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * (`2')^({b1} * (`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * (`2')^({b1} * (`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Geometric gen yhat_f= _coef[/b0] * (`2')^(_coef[/b1] * (`2')) label var yhat_f "Geometric Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Geometric " local notfit_num=`notfit_num'+1 } } if regexm("`function'","g") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * (`2')^({b1}/(`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * (`2')^({b1}/(`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto M_Geometric gen yhat_g=_coef[/b0] * (`2')^(_coef[/b1]/(`2')) label var yhat_g "Modified Geometric Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"M_Geometric " local notfit_num=`notfit_num'+1 } } if regexm("`function'","h") | regexm("`function'","ALL") { local equa1="{b0}" local equa2="_coef[/b0]" forv i=1/`count' { local equa1="`equa1'"+"+"+"{b`i'}"+"*"+"(`2')^`i'" local equa2="`equa2'"+"+"+"_coef[/b`i']"+"*"+"(`2')^`i'" } if "`initial'"=="" { nl (`1'= `equa1') if `touse', variables(`2') nolog } else { cap nl (`1'= `equa1') if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Polynomial gen yhat_h=`equa2' label var yhat_h "`count' order Polynomial Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Polynomial " local notfit_num=`notfit_num'+1 } } if regexm("`function'","i") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * ({b1}^(`2')) * ((`2')^{b2})) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * ({b1}^(`2')) * ((`2')^{b2})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Hoerl gen yhat_i=_coef[/b0] * (_coef[/b1]^(`2')) * ((`2')^_coef[/b2]) label var yhat_i "Hoerl Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Hoerl " local notfit_num=`notfit_num'+1 } } if regexm("`function'","j") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * {b1}^(1/(`2')) * ((`2')^{b2})) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * {b1}^(1/(`2')) * ((`2')^{b2})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto M_Hoerl gen yhat_j=_coef[/b0] * _coef[/b1]^(1/(`2')) * ((`2')^_coef[/b2]) label var yhat_j "Modified Hoerl Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"M_Hoerl " local notfit_num=`notfit_num'+1 } } if regexm("`function'","k") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= 1 / ({b0} + {b1} * (`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= 1 / ({b0} + {b1} * (`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Reciprocal gen yhat_k=1 / (_coef[/b0] + _coef[/b1] * (`2')) label var yhat_k "Reciprocal Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Reciprocal " local notfit_num=`notfit_num'+1 } } if regexm("`function'","l") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= 1 / ({b0} + {b1} * (`2') + {b2} * (`2')^2)) if `touse', variables(`2') nolog } else { cap nl (`1'= 1 / ({b0} + {b1} * (`2') + {b2} * (`2')^2)) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto R_Quadratic gen yhat_l=1 / (_coef[/b0] + _coef[/b1] * (`2') + _coef[/b2] * (`2')^2) label var yhat_l "Reciprocal Quadratic Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"R_Quadratic " local notfit_num=`notfit_num'+1 } } if regexm("`function'","m") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= ({b0} + {b1} * (`2'))^(-1 / {b2})) if `touse', variables(`2') nolog } else { cap nl (`1'= ({b0} + {b1} * (`2'))^(-1 / {b2})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Bleasdale gen yhat_m=(_coef[/b0] + _coef[/b1] * (`2'))^(-1 / _coef[/b2]) label var yhat_m "Bleasdale Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Bleasdale " local notfit_num=`notfit_num'+1 } } if regexm("`function'","n") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= 1 / ({b0} + {b1} * (`2')^{b2})) if `touse', variables(`2') nolog } else { cap nl (`1'= 1 / ({b0} + {b1} * (`2')^{b2})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Harris gen yhat_n=1 / (_coef[/b0] + _coef[/b1] * (`2')^_coef[/b2]) label var yhat_n "Harris Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Harris " local notfit_num=`notfit_num'+1 } } if regexm("`function'","o") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * (1 - exp(-{b1} * (`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * (1 - exp(-{b1} * (`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Exp_Association gen yhat_o=_coef[/b0] * (1 - exp(-_coef[/b1] * (`2'))) label var yhat_o "Exponential Association Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Exp_Association " local notfit_num=`notfit_num'+1 } } if regexm("`function'","p") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * ({b1} - exp(-{b2} * (`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * ({b1} - exp(-{b2} * (`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Thr_Para_Exp_Association gen yhat_p=_coef[/b0] * (_coef[/b1] - exp(-_coef[/b2] * (`2'))) label var yhat_p "Three-Parameter Exponential Association Fit" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Thr_Para_Exp_Association " local notfit_num=`notfit_num'+1 } } if regexm("`function'","q") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * (`2')/({b1} + (`2'))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * (`2')/({b1} + (`2'))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Saturation_Growth_Rate gen yhat_q=_coef[/b0] * (`2')/(_coef[/b1] + (`2')) label var yhat_q "Saturation-Growth Rate Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Saturation_Growth_Rate " local notfit_num=`notfit_num'+1 } } if regexm("`function'","r") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * exp(-exp({b1} - {b2} * (`2')))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * exp(-exp({b1} - {b2} * (`2')))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Gompertz_Relation gen yhat_r=_coef[/b0] * exp(-exp(_coef[/b1] - _coef[/b2] * (`2'))) label var yhat_r "Gompertz Relation Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Gompertz_Relation " local notfit_num=`notfit_num'+1 } } if regexm("`function'","s") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} / (1 + exp({b1} - {b2} * (`2')))^(1/{b3})) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} / (1 + exp({b1} - {b2} * (`2')))^(1/{b3})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Richards gen yhat_s=_coef[/b0] / (1 + exp(_coef[/b1] - _coef[/b2] * (`2')))^(1/_coef[/b3]) label var yhat_s "Richards Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Richards " local notfit_num=`notfit_num'+1 } } if regexm("`function'","ALL") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= ({b0} * {b1}+{b2} * (`2')^{b3})/({b1} + (`2')^{b3})) if `touse', variables(`2') nolog } else { cap nl (`1'= ({b0} * {b1}+{b2} * (`2')^{b3})/({b1} + (`2')^{b3})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto MMF gen yhat_t=(_coef[/b0] * _coef[/b1]+_coef[/b2] * (`2')^_coef[/b3])/(_coef[/b1] + (`2')^_coef[/b3]) label var yhat_t "MMF Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"MMF " local notfit_num=`notfit_num'+1 } } if regexm("`function'","u") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} - {b1}*exp(-{b2} * (`2')^{b3})) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} - {b1}*exp(-{b2} * (`2')^{b3})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Weibull gen yhat_u=_coef[/b0] - _coef[/b1]*exp(-_coef[/b2] * (`2')^_coef[/b3]) label var yhat_u "Weibull Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Weibull " local notfit_num=`notfit_num'+1 } } if regexm("`function'","v") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0}+{b1} * {b2} * cos({b2} * (`2') + {b3})) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0}+{b1} * {b2} * cos({b2} * (`2') + {b3})) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Sinusoida gen yhat_v=_coef[/b0]+_coef[/b1] * _coef[/b2] * cos(_coef[/b2] * (`2') + _coef[/b3]) label var yhat_v "Sinusoida Function" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Sinusoida " local notfit_num=`notfit_num'+1 } } if regexm("`function'","w") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} * exp((-({b1} - (`2'))^2)/(2 * {b2}^2))) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} * exp((-({b1} - (`2'))^2)/(2 * {b2}^2))) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Gaussian gen yhat_w=_coef[/b0] * exp((-(_coef[/b1] - (`2'))^2)/(2 * _coef[/b2]^2)) label var yhat_w "Gaussian Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Gaussian " local notfit_num=`notfit_num'+1 } } if regexm("`function'","x") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= {b0} + {b1} * (`2') + {b2}/(`2')^2) if `touse', variables(`2') nolog } else { cap nl (`1'= {b0} + {b1} * (`2') + {b2}/(`2')^2) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Heat_Capacity gen yhat_x=_coef[/b0] + _coef[/b1] * (`2') + _coef[/b2]/(`2')^2 label var yhat_x "Heat Capacity Model" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Heat_Capacity " local notfit_num=`notfit_num'+1 } } if regexm("`function'","y") | regexm("`function'","ALL") { if "`initial'"=="" { cap nl (`1'= ({b0} + {b1} * (`2'))/(1 + {b2} * (`2') + {b3} * (`2')^2)) if `touse', variables(`2') nolog } else { cap nl (`1'= ({b0} + {b1} * (`2'))/(1 + {b2} * (`2') + {b3} * (`2')^2)) if `touse', variables(`2') nolog initial("`initial'") } if _rc==0 & e(r2_a)>0 { est sto Rational gen yhat_y=(_coef[/b0] + _coef[/b1] * (`2'))/(1 + _coef[/b2] * (`2') + _coef[/b3] * (`2')^2) label var yhat_y "Rational Function" local fit_num=`fit_num'+1 } else { local notfit="`notfit'"+"Rational " local notfit_num=`notfit_num'+1 } } } if `fit_num'>0 { estimates table *, stats(N r2_a) t p modelwidth(11) title(Curve Estimation between "`1'" and "`2'") label var `1' "Observed" if "`nograph'"=="" { twoway (scatter `1' `2') (line yhat* `2'), title(Curve fit for `1') legend(cols(1) colgap(tiny) size(small) region(lcolor(none)) position(3)) } } qui est clear if `notfit_num'>0 { di _n as erro "Note: " as txt "Models of " as result "`notfit'" as txt "erro setting or not fit the data!" } end