Announcement

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

  • Creating missing value mechanisms

    Hi,

    I would have a full dataset with an outcome variable y and a two predictors x1 and x2 and 100 observations.

    I want to make x1 missing completely at random (MCAR) with a probability of 0.5

    Any help with the code would be greatly appreciated.

    Thank you,
    Claire

  • #2
    Claire:
    you may want to consider:
    Code:
    . set obs 100
    Number of observations (_N) was 0, now 100.
    
    . g y=runiform()
    
    . g x_1=runiform()
    
    . g x_2=runiform()
    
    . g counter=runiform()
    
    . replace x_1=. if counter>.5
    
    
    . search mcartest
    
    . mcartest x_1 x_2
    
    Little's MCAR test
    
    Number of obs       = 100
    Chi-square distance = 0.6597    
    Degrees of freedom  = 1
    Prob > chi-square   = 0.4167
    
    .
    The last test is the outcome of the community-contributed module -mcartest- (see https://journals.sagepub.com/doi/pdf...7X1301300407); as it does not reject the null, there's no evidence that missing data mechanism is not MCAR.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Thnak you Carlo, very helpful

      Comment

      Working...
      X