Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Missing values in internal rate of return calculation

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: Missing values in internal rate of return calculation Date Wed, 23 May 2012 18:44:11 +0100

```It sounds as if you might need to work on your data before you read
them into Mata, for example, by imputing or interpolating missing
values according to some sensible rule. I haven't any idea what that
sensible rule will be. Any such imputation or interpolation cannot be
assumption-free and has consequences for the rest of your analysis.

However, this is advice given in ignorance: you have said nothing

Replacing missing values by zero is always going to be wrong unless,
evidently, you know that missing means zero.

"Is it possible that Mata can somehow ignore missing values and
calculate only with the data available for each observation?"

is definitely no. If you have missing values in Mata, there is no way
that Mata can be smart on your behalf and know how you want missing
values to be treated for precisely your purposes.  This goes back to
my first comment.

Nick.

On Wed, May 23, 2012 at 6:25 PM, Tanja Berg <tanja.berg86@gmx.de> wrote:

> I want to do an internal rate of return calculation in Mata.
>
> That is what I have programmed so far:
>
> mata
> v=J(4850,50,.)
> v=st_data(.,"zspread pricenew cf1-cf16 spot1-spot16 mat1-mat16")
>
>
> pricenew=v[.,2];cf1=v[.,3];cf2=v[.,4];cf3=v[.,5];cf4=v[.,6];cf5=v[.,7];cf6=v[.,8];cf7=v[.,9];cf8=v[.,10];cf9=v[.,11];cf10=v[.,12];cf11=v[.,13];cf12=v[.,14];cf13=v[.,15];cf14=v[.,16];cf15=v[.,17];cf16=v[.,18];spot1=v[.,19];spot2=v[.,20];spot3=v[.,21];spot4=v[.,22];spot5=v[.,23];spot6=v[.,24];spot7=v[.,25];spot8=v[.,26];spot9=v[.,27];spot10=v[.,28];spot11=v[.,29];spot12=v[.,30];spot13=v[.,31];spot14=v[.,32];spot15=v[.,33];spot16=v[.,34];mat1=v[.,35];mat2=v[.,36];mat3=v[.,37];mat4=v[.,38];mat5=v[.,39];mat6=v[.,40];mat7=v[.,41];mat8=v[.,42];mat9=v[.,43];mat10=v[.,44];mat11=v[.,45];mat12=v[.,46];mat13=v[.,47];mat14=v[.,48];mat15=v[.,49];mat16=v[.,50]
>
> }
>
> for (i=1;i<=rows(v);i++) {
> }
> end
>
> The variable "zspread" is the internal rate of return I want to get.
> But I always get missing values for the zspread. I think this is the case because my data I imported from Stata includes missing values, but I can't just delete the observations with missing values because all the observations include at least one missing value.
> I tried to replace the missing values by zero, but then I get zero as a result for the "zspread".
>
> Is it possible that Mata can somehow ignores missing values and calculate only with the data available for each observation??
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```