Announcement

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

  • merging three cat var into one

    Hi! I have a question, I want to merge three categorical variables into one. One var has cases with tumor type 2, the other with tumor type 3 and the last var tumor type 4. I need to merge them into one cat var including those cases where the tumor type is undefined. Which command should I use, tried concat but think it is not for my case. Please help

  • #2
    https://journals.sagepub.com/doi/pdf...867X0800700407 was an attempt to encapsulate the main ideas, but it is difficult to tell whether any of the solutions there is quite what you need.

    You don't give a data example or explain whether the tumors are disjoint. At worst a patient may have tumors of more than one type; the code here is not invalidated if that is isn't true.

    I am going to assume that tumor2 tumor3 tumor4 are (0, 1) indicator variables. I am not going to trying to guess how undefined tumors are represented in the data. So you will probably need to give a data example still. Please do read and act on #12 at https://www.statalist.org/forums/help

    Code:
    gen tumortype = 4 * tumor2 + 2 * tumor3 + tumor4 
    
    label def tumortype 1 "4" 2 "3" 3 "3 4" 4 "2" 5 "2 4" 6 "2 3" 7 "2 3 4" 0 "none"
    
    label val tumortype tumortype
    Detail: concat() is an egen function, not a command.

    Comment


    • #3
      Hi Nick Cox
      Similar question, Merging Four cat var into one. I want to merge four variables (category1, Category2, category3, and category4). each category have 1-6 options like. Which command should I use?


      Thank you for your help

      Comment


      • #4
        #3 That's too general for me to have an opinion on an optimal answer. In fact leaving the variables as they come would be my best guess at what to do. Why do you feel inclined to combine them?


        @RIchard Goldstein points out privately that

        the code here is not invalidated if that is isn't true.
        was mangled. Sorry about that, and feel free to rephrase it to make sense.
        Last edited by Nick Cox; 15 May 2024, 08:43.

        Comment

        Working...
        X