Dear All,

I have the following rough code (it needs further amendements):

Code:
capture program drop marginteff
program define marginteff, rclass
version 10

syntax varlist(min=3 max=3 numeric fv ts), grp(varlist min=1 max=1 numeric) [MIXed] [savedata(string) savegraph(string)]
marksample touse

tokenize `varlist'
local var1="`1'" 
local var2="`2'"
local var12="`3'"

tokenize `grp'
local g="`1'"

tempname B
tempname xb
tempvar rslope
tempvar rint
tempvar cross
tempvar cross_se
tempvar m_cross
tempvar m_cross_se
tempvar m_m_cross
tempvar m_m_cross_se
tempvar t_m_cross
tempvar t_m_m_cross
tempvar rslope
tempvar rint
tempvar prob

mat `B' = e(b)
mat score double `xb' = `B' if `touse'

if "`mixed'"==""{
    qui predict `prob', pr
    qui predictnl `cross'=(_b[`var1']+_b[`var12'])*(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'+_b[`var2']+_b[`var12']*`var1'))*(1-(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'+_b[`var2']+_b[`var12']*`var1')))-_b[`var1']*(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'))*(1-(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'))) if `touse', se(`cross_se')
}

else if "`mixed'"!=""{
    qui predict `prob', mu
    qui predict `rslope' `rint' if `touse', reffect
    qui su `rslope' `rint'
    qui predictnl `cross'=(_b[`var1']+_b[`var12']+`rslope')*(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'+_b[`var2']+(_b[`var12']+`rslope')*`var1'+`rint'))*(1-(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'+_b[`var2']+(_b[`var12']+`rslope')*`var1'+`rint')))-(_b[`var1']+`rslope')*(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'+`rslope'*`var1'+`rint'))*(1-(invlogit(`xb'-_b[`var2']*`var2'-_b[`var12']*`var12'+`rslope'*`var1'+`rint'))) if `touse', se(`cross_se')
}

bysort `g': egen `m_cross'=mean(`cross') if `touse'
qui su `m_cross'
label variable `m_cross' "(Avg) Interaction term"
scalar `m_m_cross'=r(mean)
bysort `g': egen `m_cross_se'=mean(`cross_se') if `touse'
qui su `m_cross_se'
label variable `m_cross_se' "(Avg) S.E."
scalar `m_m_cross_se'=r(mean)
gen `t_m_cross'=`m_cross'/`m_cross_se' if `touse'
quietly su `t_m_cross'
label variable `t_m_cross' "(Avg) T-statistic"
scalar `t_m_m_cross'=r(mean)

if "`savedata'"!=""{
    preserve 
    keep `m_cross' `m_cross_se' `t_m_cross'
    restore
}  

if "`savegraph'"!=""{
    preserve
    twoway(scatter `m_cross' `prob')
    "`savegraph'"
    restore
}

label variable `m_cross' "Cross effect"
label variable `m_cross_se' "Standard Errors"
label variable `t_m_cross' "t-test"

su `m_cross' `m_cross_se' `t_m_cross'


di
di
di "Significance test for cross term"
di as text _dup(50) "-"
  di as text "     t-statistic  = " in  result %9.3f `m_m_cross'
  di as text "     s.e.         = " in  result %9.3f            `m_m_cross_se'
  di as text "     t-test       = " in  result %9.3f `t_m_m_cross'
  di as text "     P>|t|        = "   in  result %9.3f ttail(10000,`t_m_m_cross')
di as text _dup(50) "-"
end
I included two options *savedata* and *savegraph*. After I run my analysis, I would like to save some data in a separate file and some graphs too. I would like to be able to include within savadata option the location for where I want to save the data (specifically, New_Analysis\Results). But I am not able to do so. Specifically, I would like to have something like:

Code:
marginteff y x1 x2 x12, mixed savedata(New_Analysis\Results\dataint.dta) savegraph(New_Analysis\Results\my_graph)
How can I do that? Specifically, I cannot find the file dataint.dta in the directory I selected (there is no file dataint.dta at all on my pc). What's wrong with my code?

A second issue I have is that before generating the summariy statistics of `m_cross' `m_cross_se' `t_m_cross' I try to label them. But it seems Stata cannot do that.

Code:
 Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    __000007 |    186,443    .0121636    .0029053   .0055672   .0186525
    __000008 |    186,443    .0059492    .0016279   .0025022   .0092233
    __00000B |    186,443    2.106395    .3716783   .7090537   2.815147

Thanks for your kind help.

Dario