Announcement

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

  • newbie help on collapsing two variable collumns

    Hello all,

    I am brand new to stata and this forum has been super helpful but I don't know the correct term to even search for help with this question.
    I would like to collapse two columns of variable data. Data looks like below.

    1/2 group 2/2 group
    1 1
    2 1
    3 1
    4 1
    5 0
    6 0
    7 .
    I would like it to look like this
    full group
    1 1
    2 1
    3 1
    4 1
    5 0
    6 0
    7 .
    I would like to preserve the missing data entry. I've tried doing egen and rowtotal but I get 0's for missing data.
    Any suggestions? I'm certain this is a basic question and if its been asked multiple times I would be happy with a reference to the answer. Thanks for reading my first post.


  • #2
    The way to preserve missings (i.e. missing + missing => missing) is documented as the missing option:

    rowtotal(varlist) [, missing]
    may not be combined with by. It creates the (row) sum of the variables in varlist, treating
    missing as 0. If missing is specified and all values in varlist are missing for an observation,
    newvar is set to missing.



    Another solution is to use
    egen with rowmax().

    Comment


    • #3
      Hello Nick, very helpful thank you very much. rowmax is what I needed with another issue with similar data. I guess stata documentation almost always has the answers. Thanks for a point in the right direction.

      Comment

      Working...
      X