I need to apply some econometric methodology, and I have to consider a continuous variable among my regressors. The problem is that I just have discrete variables.
Could someone tell me how I can add small random error (residual) with mean 0 to a discrete variable (one column in my data base), and save it in my data base? I’m still a R beginner.
Example: I have
mA <- data.frame(Asexo=c(1, 0, 0, 1, 0))
and I want to add a small error to mA$Asexo so that it became a continuous variable:
mA <- data.frame(Asexocontiuous=c(1.03, 0.34, 0.18, 0, 1.5))
If you want to ‘jitter’ a 0/1 variable in order to make sure there are no duplicates (or to use a method that requires continuous variables), the simplest approach is
where
csdis your chosen standard deviation. A little more elegantly,If
sexbinaryis a factor then useas.numeric(sexbinary)(oras.numeric(sexbinary)-1if you need it to be a 0/1 rather than a 1/2 variable)You can also see
?jitter, although that is more commonly used in the context of avoiding point overlaps in graphics.