Announcement

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

  • Splitting a numerical variable into smaller variables by label

    Hello all!

    I've been struggling to find a way to split this variable (seen below in the tab format) into smaller, independent variables (by mode of transport, rather than having it all in one table) so that I can combine the walk and cycle values. I tried the split command by it gave me the error message that numerical variables aren't allowed in the varlist, and the separate command gives me the error message that the 'by(walk)' is invalid.
    Click image for larger version

Name:	Screenshot 2024-11-16 134459.png
Views:	1
Size:	15.1 KB
ID:	1767740


    Any help in splitting would be appriciated!!

  • #2
    split is for string variables where for example the distinct words of e string such as "1 2 3" or "frog toad newt" would conveniently belong in distinct new variables.

    separate is for variables you would prefer to handle according to subsets.

    Hence

    Code:
    sysuse auto, clear 
    separate mpg, by(foreign)
    will create mpg0 containing values for observations with foreign == 0 and mpg1 containing values for observations with foreign == 1.

    Before they became official commands they were community-contributed and as first author of one and single author of the other I presume I thought of both command names, but in either case that was more than 20 years ago. If the names had been the other way round, that would not have been crazy but the choice of split was certainly inspired by its use as a name in other software.

    All that said: My guess is that you don't want either. You want a coarsened version of your existing variable and should reach for recode.

    Comment

    Working...
    X