Announcement

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

  • merging variables

    Hello. I have 5 variables in my data file which are binary (dummy variables =1 or 0). I want to put them together by creating a single variable called Medical_visits. So when I will tabulate Medical_visits, I want all those 5 variables to show up. can anyone help me?

  • #2
    See

    Code:
    help reshape long
    e.g.,

    Code:
    clear
    set obs 20
    set seed 01042022
    forval i=1/5{
        gen var`i'= runiformint(0,1)
    }
    gen obs_no=_n
    reshape long var, i(obs_no) j(which)
    tab var which
    Res.:

    Code:
    . tab var which
    
               |                         which
           var |         1          2          3          4          5 |     Total
    -----------+-------------------------------------------------------+----------
             0 |         9          8         10          8         13 |        48 
             1 |        11         12         10         12          7 |        52 
    -----------+-------------------------------------------------------+----------
         Total |        20         20         20         20         20 |       100

    Comment


    • #3
      Thank you Andrew! sorry if I was unclear, but I actually want to run a multinomial regression. So I want those 5 variables to be 5 levels (categories) of a new variable called Medical_visits.

      Comment


      • #4
        Code:
        egen Medical_visits = group(dummy*)

        Comment


        • #5
          You have two guesses already from highly competent users and I could guess at yet another answer. It would be better if you gave us a data example following

          https://www.statalist.org/forums/help#stata

          As flagged there, if your data are confidential, a fake dataset with the same structure is more than fine as an example.

          Comment

          Working...
          X