// version 1.0.0 14Feb2018 // C++ mycalcs plugin for Stata #include "stplugin.h" #include #include #include #include #include "mymatrix.h" #include "mycalcsv.h" //Unicode characters can make stata names up to 32*4+1=129 bytes STDLL stata_call(int argc, char *argv[]) { ST_int first, last, nvars, nobs ; ST_int i ; ST_retcode rc ; char bname[130], vname[130], nname[130], msg[81] ; rc = static_cast(0) ; // Check that arguments are not too long for buffers for(i=0; i<3; i++) { if (strlen(argv[i])>129) { sprintf(msg, "Argument %d is more than 129 bytes long\n",i+1); SF_error(msg) ; return(static_cast(198)) ; } } // Store arguments into strings // NB: No more checking required // functions will return nonzero codes if arguments specify bad names strcpy(bname,argv[0]) ; strcpy(vname,argv[1]) ; strcpy(nname,argv[2]) ; nvars = SF_nvars() ; first = SF_in1(); last = SF_in2(); // Create bmat to hold vector of sample averages MyMatrix bmat(1, nvars) ; // Create vmat to hold VCE MyMatrix vmat(nvars, nvars) ; // Put sample averages into bmat and # of obs in nobs rc = MyAve(bmat, first, last, nvars, &nobs) ; if(rc>0) return(rc) ; // Put VCE into vmat and # of obs in n rc = MyV(bmat, vmat, first, last, nvars, nobs) ; if(rc>0) return(rc) ; // Copy sample averages from bmat to Stata matrix bname rc = bmat.CopyCtoStataMatrix(bname) ; if(rc>0) return(rc) ; // Copy VCE from vmat to Stat matrix vname rc = vmat.CopyCtoStataMatrix(vname) ; if(rc>0) return(rc) ; // Copy number of obs from n to nname rc = SF_scal_save(nname, (ST_double) nobs); if(rc>0) return(rc) ; return(rc) ; }