my thoughts:
(z <- rnorm(10)) # fake data
#replace negative values with infinite values so it looks like logpatentstock
(flogpatentstock <-ifelse(z<0,-Inf,z))
# z was faked logpatentstock , so the meanlog is mean of the positive logpatatentstock ?
(meanLog <- mean(flogpatentstock[flogpatentstock>=0]))
# apply the fix
(fixed_flogpatentstock <- ifelse( is.infinite(flogpatentstock), meanLog, flogpatentstock))