Announcement

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

  • Replacing a variable within a duplicate if the values of another variable are different between the duplicates

    Hi, I have a dataset which contains longitudinal data. For each subject, there are 2 observations, one from the first time point, one from the second (the variable subject is duplicated). I am trying to replace Var1 with the value 1 only if the values of Var2 are different between the two subject duplicates (i.e. if the value for Var2 changes from the first time point to the second for any given subject). I would be very grateful for some help with coding this! Thanks.

  • #2
    Liz:
    you may want to try:
    Code:
    bysort id: replace var1=1 if var2[1]!=var2[2]
    where -id- reads your -subjects-.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you so much Carlo, that worked.

      Comment

      Working...
      X