Announcement

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

  • Apply values across all in the same group

    Hi all, I have a dataset of about 10k participants across 600 groups (ParentSiteID in the dataset). I have a status update (status=1) for 118 participants that need to be applied to all members of their group (ParentSiteID). How can I do this? Thanks!

  • #2
    Tiara:
    do you mean something along the lines of the following toy-example?
    Code:
    . set obs 5
    number of observations (_N) was 0, now 5
    
    . g Group=1
    
    . g flag=1 in 1
    
    
    . expand 2
    
    
    . replace Group=2 in 6/10
    
    
    . replace flag=1 in 7
    
    
    . bysort Group: replace flag=1 if flag==.
    
    
    . list
    
         +--------------+
         | Group   flag |
         |--------------|
      1. |     1      1 |
      2. |     1      1 |
      3. |     1      1 |
      4. |     1      1 |
      5. |     1      1 |
         |--------------|
      6. |     2      1 |
      7. |     2      1 |
      8. |     2      1 |
      9. |     2      1 |
     10. |     2      1 |
         +--------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Tiara, it depends on the current values of status for other participants. If the status is missing (.) for other participants, just run the following codes.

      Code:
      bys ParentSiteID (status): replace status = status[_n-1] if status[_n-1] == 1
      If not, then you may change their values to missing first.

      Comment


      • #4
        Thank you, Fei Wang! It worked perfectly!
        __

        Originally posted by Fei Wang View Post
        Tiara, it depends on the current values of status for other participants. If the status is missing (.) for other participants, just run the following codes.

        Code:
        bys ParentSiteID (status): replace status = status[_n-1] if status[_n-1] == 1
        If not, then you may change their values to missing first.

        Comment


        • #5
          Thanks, Carlo. That's not quite it, but I appreciate your help. Fei Wang provided the code I need.

          Thank you again!
          ___

          Originally posted by Carlo Lazzaro View Post
          Tiara:
          do you mean something along the lines of the following toy-example?
          Code:
          . set obs 5
          number of observations (_N) was 0, now 5
          
          . g Group=1
          
          . g flag=1 in 1
          
          
          . expand 2
          
          
          . replace Group=2 in 6/10
          
          
          . replace flag=1 in 7
          
          
          . bysort Group: replace flag=1 if flag==.
          
          
          . list
          
          +--------------+
          | Group flag |
          |--------------|
          1. | 1 1 |
          2. | 1 1 |
          3. | 1 1 |
          4. | 1 1 |
          5. | 1 1 |
          |--------------|
          6. | 2 1 |
          7. | 2 1 |
          8. | 2 1 |
          9. | 2 1 |
          10. | 2 1 |
          +--------------+
          
          .

          Comment

          Working...
          X