Announcement

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

  • #16
    Hi all,

    Sorry for being late to the thread but I have a question very similar to Candace. Suppose I want to do the same exact thing but I have several time points and thousands of individual observations. Is there a way to turn all nulls for an individual into 'Yes' if one time point for the individual ='Yes'.

    Thanks!
    Paul

    Comment


    • #17
      What's null in this context? An empty string? A space? Something else?

      You can find any "Yes" answers with

      Code:
      bysort id : egen any_yes = max(answer == "Yes")
      The principle that "any" means max() and "all" means min() is discussed at https://www.stata.com/support/faqs/d...ble-recording/

      The same recipe should work for other answers, subject to details on leading and trailing spaces, use of upper and lower case, and so on. So suppose the possibilities are Yes, No, and some other signal that means no reply.

      Then you could expand on that recipe to get (details on tolerating spaces and case variations may or may not be needed)

      Code:
      bysort id : egen any_yes = max(trim(lower(answer)) == "yes") 
      bysort id : egen any_yes = max(trim(lower(answer)) == "yes")
      and then your rules might be

      Code:
      clonevar ANSWER = answer 
      replace ANSWER = "Yes" if any_yes == 1 & any_no == 0 
      replace ANSWER = "No" if any_no == 1 & any_yes == 0
      I advise working on a copy of the original variable in case (1) you change your mind (2) you mess up (3) someone insists that you don't do that.



      Comment

      Working...
      X