Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create variables from a categorical variable

    I have a variable with many categories and want to create new variables for each one. Is there a way to not do it one by one?
    Thank you



    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	33.5 KB
ID:	1688266

  • #2
    There is a good chance you don't actually need this. Many commands like sum and estimation commands like regress, logit etc accept factor variable specifications that allow you to specify something like i.varname , and they will automatically generate the indicator variables needed on the fly. You might want to check
    Code:
    help fvvarlist
    However, you can only use the i. operator on numerical variables, so if your current variable is string, you may want to first convert it to numeric using encode. See
    Code:
    help encode
    If you do still want to create indicators, one option might be to use the generate() option to the tab command: see
    Code:
    help tabulate oneway
    Last edited by Hemanshu Kumar; 05 Nov 2022, 15:15.

    Comment

    Working...
    X