Description Usage Arguments Details Value Author(s) Examples
egen() transforms a numeric vector to a factor vector.
1 |
data |
data.frame |
var |
existing variable |
cut |
either a number or a numeric vector |
lbl |
labels to specify |
new_var |
name of new variable to be created |
egen allows easy conversion of a numerical variable to a categorical
variable.
If only a number is specified in cut, it categorizes
into equal intervals based on that number. If no value is set
for cut, the default interval is 10.
Automatic naming new variable
If new_var is not specified, new names will be automatically
created by appending _cat as suffix.
VARNAME`_cat`
Automatic Labelling
If lbl is not specified, labels are constructed in
`##-##`.
data.frame
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | x <- egen(infert, age)
tab(x, age_cat)
## Not run:
## Set cut-off points
x <- egen(infert, age, c(26, 31, 36, 41))
tab(x, age_cat)
## Add labels and give a new name
x <- egen(infert, age, c(26, 31, 36, 41),
lbl = c("<= 25", "26 - 30", "31 - 35",
"36 - 40", "41+"),
new_var = age_grp)
tab(x, age_grp)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.