<div dir="ltr"><div><div>Hello,<br></div>The following code works well in R:<br>attach(dataqtr)<br><br>dataqtr <- data.table(dataqtr)<br>setkeyv(dataqtr,c("gvkey","qtr"))<br><br>vec_growth <- data.frame(0,0,0,0,0,0,0,0,0,0,0,0,0)<br>
vec_eps    <- data.frame(0,0,0,0,0,0,0,0,0,0,0,0,0)<br><br>T <- 15<br><br>for (i in 1:nrow(dataqtr)) {<br>  vec_growth[i,] <- ( dataqtr[i,LTG] * exp(1:(T-2)/(T-1)*log( dataqtr[i,meanLTG] / dataqtr[i,LTG] )))<br>  <br>
}<br><br><br></div><div>However I am not able to reproduce it using the following Rccp code:<br><br>a<- dataqtr[,LTG]<br>b<- dataqtr[,meanLTG]<br><br>src <-'<br> Rcpp::NumericVector a(aa);<br> Rcpp::NumericVector b(bb);<br>
 Rcpp::NumericMatrix Am (A);<br> int n = a.size();<br> int m = b.size();<br> int T=15;<br> <br> int nrows = Am.nrow();<br> int ncol  = Am.ncol();<br> <br>     for (int ii = 1; ii < nrows; ii++) {<br>        for (int jj = 1; jj<ncol; jj++)  {<br>
        Am[ii,jj] =  a[jj] * exp(jj/(T-1)*log( b[jj] / a[jj] )); <br>        }}<br>return Am;<br>'<br>fun <- cxxfunction(signature(aa="numeric", bb="numeric",A="numeric"), body = src, plugin="Rcpp")<br>
<br>A<-matrix(data=NA,nrow=100,ncol=13)<br>fun(a,b,A)<br><br></div><div>I don't understand the error. <br><br>Thanks!<br></div></div>