Search code examples
rregressionpaneltransformationnegative-number

Log transformation function in R


I would like to perform a panel data regression. Before that, I calculate the natural logarithm of my variables. Since some variables are negative, the logarithm produces some NAs. At this point I would like to apply a transformation function so that no data is lost, basically like that:

Ln(1+EBIT),if EBIT≥ 0 and -Ln(1-EBIT),if EBIT<0

Can anyone help me with the code?


Solution

  • function(EBIT) sign(EBIT)*log(1+abs(EBIT))