Announcement

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

  • How to xfill (or workaround) to overcome data inconsistencies

    Hi there, I have a data set with about 50k records with multiple survey records per person. I want to xfill on key variables (demographics and other characteristics). However, there are inconsistencies (e.g., person A completes 3 surveys, one time they live in GA the next time they live in FL, and the third time they don't answer the question). The xfill command won't execute when the data are inconsistent by id. I developed a workaround (reshaping the data to wide and looking across rows to fill using loops) but it's clunky. Is there another way to achieve this? Thanks!
    Last edited by Kathleen Carluzzo; 19 Oct 2022, 11:16.

  • #2
    I'm not sure I understand. When I type help xfill the Viewer window tells me the following.
    Click image for larger version

Name:	xfill3.png
Views:	1
Size:	69.9 KB
ID:	1685987
    With that said, perhaps you would find the community-contributed fillmissing command useful.
    Code:
    sse describe fillmissing
    Last edited by William Lisowski; 19 Oct 2022, 13:02.

    Comment


    • #3
      There is, or used to be, an xfill at www.sealedenvelope.com
      but I can’t get Stata to talk to that site.

      As I recall
      xfill replaces missing values by single non-missing values if and only if just one distinct non-missing value is in evidence. That is false for your example and so you need a different rule, which might be copy last non-missing value.

      https://www.stata.com/support/faqs/d...issing-values/

      is an FAQ.
      Last edited by Nick Cox; 20 Oct 2022, 07:16.

      Comment


      • #4
        For what it's worth I just successfully installed xfill from the site in post #2 and confirmed that xfill is not appropriate for this task. The FAQ is authoritative on filling in missings without relying on anything other than base Stata.
        Code:
        . net from https://www.sealedenvelope.com/
        ------------------------------------------------------------------------------------------------
        https://www.sealedenvelope.com/
        Programs from Sealed Envelope Ltd
        ------------------------------------------------------------------------------------------------
        
        These programs are provided by Sealed Envelope Ltd.
        For more details on their use visit www.sealedenvelope.com
        
        PACKAGES you could -net describe-:
            hl                Hosmer-Lemeshow goodness of fit test
            mlogplot2         Extension to mlogplot to handle two-way interaction terms in mlogit
            reformat          Reformat regression output
            rescale           Rescale categorical variables using numbers found in value labels
            time              Convert strings in HH:MM:SS format to elapsed times and back again
            xcount            Count longitudinal data
            xfill             Fill in static variables in longitudinal data
            xtab              Tabulate longitudinal data
        ------------------------------------------------------------------------------------------------
        
        . net describe xfill
        
        ------------------------------------------------------------------------------------------------
        package xfill from https://www.sealedenvelope.com
        ------------------------------------------------------------------------------------------------
        
        TITLE
              Fill in static variables in longitudinal data.
        
        DESCRIPTION/AUTHOR(S)
              xfill 'fills in' missing values of static variables in
              longitudinal datasets. A static variable is one that is constant
              in multiple record data, such as patient gender in a series of
              follow-up visits on the same patient.
              
              Author: Tony Brady, Sealed Envelope Ltd.
              Distribution-Date: 25oct2012
        
        INSTALLATION FILES                                (type net install xfill)
              stata/xfill.ado
              stata/xfill.hlp
        ------------------------------------------------------------------------------------------------
        
        . net install xfill
        checking xfill consistency and verifying not already installed...
        installing into /Users/lisowskiw/Library/Application Support/Stata/ado/plus/...
        installation complete.
        
        .

        Comment

        Working...
        X