Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: plugin for C++?


From   "Salah Mahmud" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: plugin for C++?
Date   Tue, 8 Jul 2003 10:15:00 -0400

Shige Song wrote:
> 
> Could you please post a simple code example of how to code pascal
using
> the Stata plugin? I am very interested, thanks!
> 
> Shige Song
> Department of Sociology, UCLA

Below is a Delphi translation of varsum.c
http://www.stata.com/support/plugins/stplugin.c. Compiling this file
using any Delphi 2 or higher would result in varsum.plu (a Windows DLL).
testvarsum.ado (at the bottom of this message) could be then used to
test the DLL. Notice the reference to 'stplugin.pas' in the uses
statement. This is a Pascal translation of stplugin.h and stplugin.c. I
could not include this file before clarifying copyright and other issues
with the good people of Stata. If all goes well, I will make the full
package available for download.

 
Salah Mahmud
Division of Cancer Epidemiology
Department of Oncology, McGill University
Gerald Bronfman Centre
546 Pine Avenue West
Montreal, Quebec
Canada H2W 1S6
[email protected]
 


---------------------------- Varsum.dpr----------------------------

library varsum;


uses
  SysUtils,
  stplugin in 'stplugin.pas'; //'stplugin.pas' not included

{$E plugin}


function stata_call(argc: integer; argv:PTAnsiStringArray): STDLL;cdecl;
var
 j,k : ST_int;
 sum,z : ST_double;
begin
    if(SF_nvars() < 2) then
    begin
         Result:=102;
         exit ;          //* not enough variables specified */
    end;
   j := SF_in1();
   while j <= SF_in2 do
   begin
       if(SF_ifobs(j)=bTrue) then
       begin
          sum := 0.0 ;
          for k:=1 to SF_nvars()-1 do
          begin
             Result := SF_vdata(k,j,@z);
             if(Result>0) then exit;
             sum := sum+ z ;
          end;
          Result:=SF_vstore(SF_nvars(), j, sum);
          if(Result>0) then exit;
       end;
     inc(j);
   end;
  Result:=0;
end;

exports
  pginit     index 1,
  stata_call index 2;

begin
end.


---------------------------- testvarsum.ado----------------------------
program testvarsum
	version 8.1
        syntax varlist [in] [if]
        plugin call varsum `varlist' `in' `if'
end

program varsum, plugin using(varsum.plu)
------------------------------------------------------------------------

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index