Announcement

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

  • Questions for "drop" participants in long data format for repeated mesurements.

    Hello! I'd like to ask how to drop observations in such follwing dataset.

    See the pic below for dataset.
    ID is the identifier of participants, visit is the visit namely visit 1 or visit 2.
    Some participants are missing at visit 1 and some are at visit 2, and some values for Blood and urine are missing.

    I want to drop all participants if they have missing value both for Blood and urine at visit 1.
    I'd like to know if there can be some straightforward and simple method in doing that.

    And I can only use the simple code to list the ID by : list ID if Blood==. & urine==.
    But since it's a large dataset, it is not practical and also not clever to delete them one after one, like drop if ID==512125 and so on... also with more than 100 variables also not possible for reshaping.

    Thanks for help!!!

    Click image for larger version

Name:	te.png
Views:	1
Size:	22.3 KB
ID:	1478961





  • #2
    Yes, there's a straightforward way to do this:
    Code:
    gen mymiss = (visit ==1) & missing(blood) & missing(urine)
    After which you could do
    Code:
    drop if mymiss
    but it's likely better to do:
    Code:
    regress y x if !mymiss
    // or
    tabulate y x if !mymiss

    Suggestions:
    1) See the StataList FAQ about not posting pictures, and about using -dataex- to show data.
    2) Learn about logical expressions at https://www.stata.com/support/faqs/d...rue-and-false/
    3) Read about the missing() function
    3) There's usually no need to actually drop data in Stata. See -help if-, which can be used with almost any command.
    4) Read about -drop-.

    Comment


    • #3
      Originally posted by Mike Lacy View Post
      Yes, there's a straightforward way to do this:
      Code:
      gen mymiss = (visit ==1) & missing(blood) & missing(urine)
      After which you could do
      Code:
      drop if mymiss
      but it's likely better to do:
      Code:
      regress y x if !mymiss
      // or
      tabulate y x if !mymiss

      Suggestions:
      1) See the StataList FAQ about not posting pictures, and about using -dataex- to show data.
      2) Learn about logical expressions at https://www.stata.com/support/faqs/d...rue-and-false/
      3) Read about the missing() function
      3) There's usually no need to actually drop data in Stata. See -help if-, which can be used with almost any command.
      4) Read about -drop-.
      Thank you for your reply, I will noted these things next time, but this data is a fake data I created so no sensitive issues.
      But actually what I'd like to do is delete all data from that participants, like drop if ID==5, but by your code suggested, it will only help delete if ID==5 & visit==1, but for visit==2 & ID==5, the observations are still there.
      I know actually is not so necessary to delete that observations, but it can be a lot useless information in the dataset.

      Comment


      • #4
        Check whether this is not doing what you want:

        Code:
        . sort id visit
        
        . by id: gen tag = missing(blood[1]) | missing(urine[1])
        
        . drop if tag

        Comment

        Working...
        X