I used the exact same code as your last posted code, however, instead of dropping the first 2 months I changed the 2 values into a . so that it resembled my dataset
Code:
clear all input str20 date chg 31jan2006 . 28feb2006 . 31mar2006 .0356 28apr2006 -.0124 31may2006 -.0304 30jun2006 -.0054 31jul2006 -.0399 31aug2006 .0083 29sep2006 -.0123 31oct2006 .0164 30nov2006 .0077 29dec2006 -.0089 end gen date2 = date(date, "DMY") format date2 %td gen year = year(date2) gen idcode = 1 sort idcode date2 list set type double *Lydia code gen chgdec1 = chg+1 //Take log gen logchgdec1 = log(chgdec1) //Sum them up gen sumchg1 = sum(logchgdec1) //Exp gen expsumchg1 = exp(sumchg1) //Annualize gen annual1 = expsumchg1^(12/_N)-1 * RW Code bysort idcode year: egen numvalid = total(!missing(chg)) bysort idcode year: egen sumchg = total(log(chg + 1)) bysort idcode year: gen annual = exp(sumchg) ^ (12/numvalid) - 1 list date2 chg numvalid annual1 annual
Comment