Dear All,
I have the following program, which I adapted starting from user-written utest. Still it needs to be developed:
Among other things, I incuded the lines in red to perform a non-linear test on some parameters. The routine works fine a part from the lines in red. After execution, I get:
So the S.E. and other elements are not reported. However, if I try to run the command outside the program, I get:
So my question is why in the first case I did not get a complete table. The command is a test for curvilinear relationship with interaction term and the non-linear test I am trying to perform follows the instructions in Haans, R. F. J., Pieters, C., & He, Z. (2016).
Thanks in advance.
Dario
I have the following program, which I adapted starting from user-written utest. Still it needs to be developed:
Code:
capture program drop utest01
program define utest01, rclass
version 9
syntax varlist(min=4 max=4 numeric), INTeraction(varlist min=1 max=1 numeric) [MInimum(real -.12345) MAximum(real .12345) Fieller High Sd(numlist min=1 max=1) Level(cilevel)]
tokenize `varlist'
local var1="`1'"
local var2="`2'"
local var3="`3'"
local var4="`4'"
tokenize `interaction'
local M1= "`1'"
local df=e(df_r)
if `df'==. {
local df=e(N)
}
mat beta=e(b)
mat covar=e(V)
mat b1=beta[1,"`var1'"]
local b1=b1[1,1]
mat b2=beta[1,"`var2'"]
local b2=b2[1,1]
mat b3=beta[1,"`var3'"]
local b3=b3[1,1]
mat b4=beta[1,"`var4'"]
local b4=b4[1,1]
mat s11=covar["`var1'","`var1'"]
mat s22=covar["`var2'","`var2'"]
mat s33=covar["`var3'","`var3'"]
mat s44=covar["`var4'","`var4'"]
mat s12=covar["`var1'","`var2'"]
mat s13=covar["`var1'","`var3'"]
mat s14=covar["`var1'","`var4'"]
mat s23=covar["`var2'","`var3'"]
mat s24=covar["`var2'","`var4'"]
mat s34=covar["`var3'","`var4'"]
local s11=s11[1,1]
local s22=s22[1,1]
local s33=s33[1,1]
local s44=s44[1,1]
local s12=s12[1,1]
local s13=s13[1,1]
local s14=s14[1,1]
local s23=s23[1,1]
local s24=s24[1,1]
local s34=s34[1,1]
qui su `M1'
local Zbar=r(mean)
nlcom ((`b1'*`b4')-(`b2'*`b3'))/(2*(`b2'+`b4'*`Zbar')^2)
mat test = r(b)
mat table = r(table)
mat tes=test[1,1]
local tes=tes[1,1]
mat valuep=table[4,1]
local valuep=valuep[1,1]
qui su `var1'
if `minimum'==-.12345 {
local x_min=r(min)
}
else {
local x_min=`minimum'
}
if `maximum'==.12345 {
local x_max=r(max)
}
else {
local x_max=`maximum'
}
#delimit ;
local A=(`b1')+(`b3')*(`Zbar');
local B=(`b2')+(`b4')*(`Zbar');
local var_A=`s11'+(`s33')*((`Zbar')^2)+2*((`s13')*(`Zbar'));
local var_B=`s22'+(`s44')*((`Zbar')^2)+2*((`s24')*(`Zbar'));
local cov_AB=(`s12'+(`s14')*(`Zbar')+(`s23')*(`Zbar')+(`s34')*((`Zbar')^2));
local t_min=(`A'+(2*(`x_min')*(`B')))/sqrt(`var_A'+4*(`var_B')*(`x_min')^2+4*(`x_min')*(`cov_AB'));
local sl_min=(`A')+(2*(`B')*(`x_min'));
local t_max=(`A'+(2*(`x_max')*(`B')))/sqrt(`var_A'+4*(`var_B')*(`x_max')^2+4*(`x_max')*(`cov_AB'));
local sl_max=(`A')+((2*(`B'))*(`x_max'));
local top=-(`A')/(2*(`B'));
#delimit cr
local shape="U-shape"
local h0shape=" (vs. H0:monotone or inverse U-shape.)"
if `t_min' > `t_max' {
local shape="inverse U-shape"
local h0shape=" (vs. H0:monotone or U-shape.)"
}
di
di as text "Specification: f(x)=x^2"
di as text "Extreme point: " in result %9.0g `top'
di
di as text "Test:"
di as text " H1: `shape'"
di as text " vs. H0: Monotone or `h0shape'"
di
local t_sac=min(abs(`t_min'),abs(`t_max'))
di in text "{hline 17}{c TT}{hline 31}"
di in text %-17s " " "{c |} Lower bound Upper bound"
di in text "{hline 17}{c +}{hline 31}"
di as text %-17s "Interval" "{c |} " in result %9.0g `x_min' " " %9.0g `x_max'
di as text %-17s "Slope" "{c |} " in result %9.0g `sl_min' " " %9.0g `sl_max'
if (`t_min')*(`t_max')>0 {
di in text "{hline 17}{c BT}{hline 31}"
di
di as text "Extremum outside interval - trivial failure to reject H0"
return scalar t=.
return scalar p=.
}
else {
di as text %-17s "t-value" "{c |} " in result %9.0g `t_min' " " %9.0g `t_max'
di as text %-17s "P>|t|" "{c |} " in result %9.0g ttail(`df',abs(`t_min')) " " %9.0g ttail(`df',abs(`t_max'))
di in text "{hline 17}{c BT}{hline 31}"
di
di as text "Overall test of presence of a " "`shape'" ":"
di as text " t-value = " in result %9.2f `t_sac'
di as text " P>|t| = " in result %9.3g ttail(`df',`t_sac')
return scalar t=`t_sac'
return scalar p=ttail(`df',`t_sac')
di
di as text "Test for shift of the turning point" ":"
di as text " t-value = " in result %9.2f `tes'
di as text " P>|t| = " in result %9.3g `valuep'
return scalar shift=`tes'
return scalar shift_p=`valuep'
}
return scalar x_l=`x_min'
return scalar x_u=`x_max'
return scalar s_l=`sl_min'
return scalar s_u=`sl_max'
return scalar t_l=`t_min'
return scalar t_u=`t_max'
return scalar extr=`top'
return local shape="`shape'"
* Calculation of Fieller interval
if "`fieller'"!="" {
di
local df=e(df_r)
if `df'==. {
local df=e(N)
}
}
local alpha=1-`level'/100
local T=invttail(`df',.5*`alpha')
#delimit ;
local d=((`cov_AB')^2-(`var_A')*(`var_B'))*`T'^2+(`B')^2*(`var_A')+(`A')^2*(`var_B')
-2*(`A')*(`B')*(`cov_AB');
#delimit cr
* simplest case: interval away from inf
if `d'>0 & ((`B')^2-`var_B'*`T'^2)>0 {
local theta_l=(-(`cov_AB')*`T'^2+(`A')*(`B')-`T'*sqrt(`d')) / ((`B')^2-(`var_B')*`T'^2)
local theta_h=(-(`cov_AB')*`T'^2+(`A')*(`B')+`T'*sqrt(`d')) / ((`B')^2-(`var_B')*`T'^2)
di as text 100*(1-`alpha') "% Fieller interval for extreme point: " in result "[" -0.5*`theta_h' "; " -0.5*`theta_l' "]"
}
* interval covers inf
if `d'>0 & ((`B')^2-`var_B'*`T'^2)<0 {
local theta_l=(-`cov_AB'*`T'^2+(`A')*(`B')-`T'*sqrt(`d')) / ((`B')^2-`var_B'*`T'^2)
local theta_h=(-(`cov_AB')*`T'^2+(`A')*(`B')+`T'*sqrt(`d')) / ((`B')^2-(`var_B')*`T'^2)
di as text 100*(1-`alpha') "% Fieller interval for extreme point: " in result "[-Inf;" -0.5*`theta_h' "] U [" -0.5*`theta_l' ";+Inf]"
}
* interval covers R
if `d'<0 {
local theta_l=(-`cov_AB'*`T'^2+(`A')*(`B')-`T'*sqrt(`d')) / ((`B')^2-`var_B'*`T'^2)
local theta_h=(-(`cov_AB')*`T'^2+(`A')*(`B')+`T'*sqrt(`d')) / ((`B')^2-(`var_B')*`T'^2)
di in text 100*(1-`alpha') "% Fieller interval for extreme point: " as result "[-Inf; +Inf]"
}
end
Code:
------------------------------------------------------------------------------ lnfdipccu~qd | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- _nl_1 | -.0279467 . . . . . ------------------------------------------------------------------------------
Code:
------------------------------------------------------------------------------ lnfdipccu~qd | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- _nl_1 | -.0279467 .0534252 -0.52 0.601 -.1326582 .0767648 ------------------------------------------------------------------------------
Thanks in advance.
Dario
Comment