Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Plugins, another strange behavior


From   Kevin Crow <[email protected]>
To   [email protected]
Subject   Re: st: Plugins, another strange behavior
Date   Tue, 15 Jan 2008 10:08:06 -0600

Sergiy reported a possible bug with Stata plugins in regards to missing values. I could not reproduce the bug using a C plugin.

******************LOG**********************
. cap program drop printout

. program printout, plugin

.
. use sergiy, clear

. list

+-----------------+
| w r x y |
|-----------------|
1. | 1 1 1 101 |
2. | 1 1 2 102 |
3. | 1 1 3 103 |
4. | 1 1 0 . |
5. | 1 1 5 105 |
|-----------------|
6. | 1 1 6 106 |
7. | 1 1 7 107 |
8. | 1 1 8 108 |
9. | 1 1 9 109 |
10. | 1 1 . 100 |
+-----------------+

. plugin call printout w r x y
The value of x[1] is 1.000000
The value of x[2] is 2.000000
The value of x[3] is 3.000000
The value of x[4] is 0.000000
The value of x[5] is 5.000000
The value of x[6] is 6.000000
The value of x[7] is 7.000000
The value of x[8] is 8.000000
The value of x[9] is 9.000000
The value of x[10] is 898846567431157953864652595394512366808988489471153286367
*******************************************

******************C-Code**********************
#include <stdio.h>
#include "stplugin.h"

STDLL stata_call(int argc, char *argv[])
{
char buf[80] ;
ST_int j ;
ST_double z ;

for(j = SF_in1(); j <= SF_in2(); j++) {
if(SF_ifobs(j)) {
(void) SF_vdata(3, j, &z) ;
snprintf(buf, 80, "The value of x[%d] is %lf\n", j, z) ;
SF_display(buf) ;
}
}
return(0) ;
}
**********************************************

Sergiy, it might be best if you emailed me at [email protected] so that we can look into the problem further.

Kevin Crow - StataCorp

Sergiy Radyakin wrote:

Hello Stata users,

the following strange issue was discovered while writing a plugin to
process the dataset currently in Stata's memory. It seems that
casewise deletion of observations with missing values of variables
passed on to the plugin is forced by Stata.

Consider the following example:

       w   r   x     y
  1.   1   1   1   101
  2.   1   1   2   102
  3.   1   1   3   103
  4.   1   1   0     .
  5.   1   1   5   105
  6.   1   1   6   106
  7.   1   1   7   107
  8.   1   1   8   108
  9.   1   1   9   109
 10.   1   1   .   100


Variables x and y each have a missing value, though in different observations.

An extract from the code (Delphi) which illustrates the problem follows:

for i:=SF_in1 to SF_in2 do if SF_ifobs(i)=bTrue then
           SF_Display(PChar('Processing observation: '+IntToStr(i)+'{break}'));

The code loops through all observations from lower "in" value to upper
"in" value and if the observation satisfies the "if" condition it's
index is sent to Stata's output window.

As a result we have:

Processing observation: 1
Processing observation: 2
Processing observation: 3
Processing observation: 5
Processing observation: 6
Processing observation: 7
Processing observation: 8
Processing observation: 9

Where observations 4 (the one with the missing y) and 10 (the one with
the missing x) are not listed. No "if"-condition was specified, and
according to the manual for plugin-developers the function SF_ifobs()
must return "True" for all observations.

Both Stata 9 and Stata 10 show identical behavior in this issue. Is
this supposed to be so? Is it controllable? How can one access x[4]
and y[10] in this example?

Thank you,
    Sergiy Radyakin
    Consultant, DECRG, The World Bank.
*
*   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/



*
*   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