Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From   Nick Cox <[email protected]>
To   [email protected]
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
about exactly why missing values arise in your application.

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

The short answer to

"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 <[email protected]> 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")
>
> function y(zspread,v) {
>
> 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]
>
> return(pricenew-((cf1/(1+spot1+zspread)^mat1)+(cf2/(1+spot2+zspread)^mat2)+(cf3/(1+spot3+zspread)^mat3)+(cf4/(1+spot4+zspread)^mat4)+(cf5/(1+spot5+zspread)^mat5)+(cf6/(1+spot6+zspread)^mat6)+(cf7/(1+spot7+zspread)^mat7)+(cf8/(1+spot8+zspread)^mat8)+(cf9/(1+spot9+zspread)^mat9)+(cf10/(1+spot10+zspread)^mat10)+(cf11/(1+spot11+zspread)^mat11)+(cf12/(1+spot12+zspread)^mat12)+(cf13/(1+spot13+zspread)^mat13)+(cf14/(1+spot14+zspread)^mat14)+(cf15/(1+spot15+zspread)^mat15)+(cf16/(1+spot16+zspread)^mat16)))
> }
>
> for (i=1;i<=rows(v);i++) {
> r=mm_root(zspread=.,&y(),0,1,1e-9,1000,v[i,.])
> v[i,1]=zspread
> }
> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index