I have been using Stata and the loops are easily executed there. However, in R I have faced some errors in looping over variables. I tried some of the codes over here and it does not work. Basically, I am trying to clean the data by logging the values. I had to convert negative values to positive first before logging them.

I intend to loop over multiple firm statistics on the dataframe but I faced errors in doing so.

```
varlist <- c("revenue", "profit", "cost")`

for (v in varlist) {
  data$log_v <- log(abs(ifelse(data$v>1, data$v, NA)))
  data$log_v <- ifelse(data$v<0, data$log_v*-1,data$log_v)
}

```

> 
> Error in $<-.data.frame(*tmp*,"log\_v", value = numeric(0)) : replacement has 0 rows, data has 9
> 
> 
>