// version 1.0.0 14Feb2018 #include "stplugin.h" #include #include #include #include STDLL stata_call(int argc, char *argv[]) { ST_int first, last, nVars, i, j, nObs ; ST_double value ; ST_retcode rc ; int nchar ; char line[81], msg[81], svalue[26] ; std::string line2 ; rc = (ST_retcode) 0 ; // Put the first observation in sample into first first = SF_in1 (); // Put the last observation in sample into last last = SF_in2 (); // Put number of variables in varlist passed in to plugin into nVars nVars = SF_nvars() ; // Initiate number of observations counter to 0 nObs = 0 ; // Loop over observations for(i=first; i<=last; i++) { line2 = ""; // Only display observations for which if restriction is true if (!SF_ifobs(i)) { continue ; } // Increment number of observations counter ++nObs ; // Loop over variables for(j=1; j<=nVars; j++) { // Put value of observation i on variable j into value rc = SF_vdata(j, i, &value); // Return with error if problem getting value if(rc>0) { sprintf(msg, "Problem accessing Stata data\n") ; SF_error(msg) ; return(rc) ; } // Return with error if missing value if (SF_is_missing(value)) { sprintf(msg, "missing values encountered\n") ; SF_error(msg) ; return( (ST_retcode) 416 ) ; } snprintf(svalue,25,"%f ",value) ; line2 = line2 + svalue ; } // Display line or error message in Stata if (line2.length()<=80) { line2 = line2 + "\n" ; strcpy(line, line2.c_str()) ; SF_display(line) ; } else { sprintf(msg, "More than 80 bytes in line\n") ; SF_error(msg) ; return( (ST_retcode) 498 ) ; } } sprintf(line, "First observation was %d\n", first) ; SF_display(line) ; sprintf(line, "Last observation was %d\n", last) ; SF_display(line) ; sprintf(line, "Number of observations listed was %d\n", nObs) ; SF_display(line) ; return(rc) ; }