Announcement

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

  • New on SSC: markobs

    Thanks to Kit Baum, a new command, markobs, is now available from the SSC.

    markobs is intended as a safe wrapper for mark and markout, helping to avoid accidential overwriting of variables. markobs originated from a discussion with Dirk Enzmann, who also reviewed the code and help file.

    Here's a toy example to demonstrate the problem
    Code:
    . sysuse auto
    (1978 automobile data)
    
    . tabulate foreign
    
     Car origin |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         52       70.27       70.27
        Foreign |         22       29.73      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    
    . tabulate rep78
    
         Repair |
    record 1978 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |          2        2.90        2.90
              2 |          8       11.59       14.49
              3 |         30       43.48       57.97
              4 |         18       26.09       84.06
              5 |         11       15.94      100.00
    ------------+-----------------------------------
          Total |         69      100.00
    
    . tempvar touse
    
    . mark `touse'
    
    . markout `tose' foreign rep78 // <- misspelled `touse'
    
    . count if `touse' // <- want 69
      74
    
    . tabulate foreign
    
     Car origin |      Freq.     Percent        Cum.
    ------------+-----------------------------------
       Domestic |         53       71.62       71.62
        Foreign |         21       28.38      100.00
    ------------+-----------------------------------
          Total |         74      100.00
    Above, we load auto.dta and look at the distribution of foreign and rep78. We then create a temporary variable, touse (read: to-use), to indicate the sample we wish to use in subsequent code. We intend to set the marker variable to 0 for observations with missing values in foreign or rep78. Unfortunately, we misspell touse (omitting the u in tose). Even worse, markout doesn't complain. We're left with a sample of all 74 observations, whereas we wanted 69 observations because rep78 has 5 missing values, and -- much worse -- markout has changed the (byte) variable foreign!

    Here's how markobs solves this problem:
    Code:
    . sysuse auto
    (1978 automobile data)
    
    . tempvar touse
    
    . markobs `touse'
    
    . markobs `tose' foreign rep78 // <- misspelled `touse'
    foreign not created by markobs
    r(498);
    Naturally, the 0/1 to-use variable created by markobs can be used with markin and svymarkout.
    Last edited by daniel klein; 11 Sep 2025, 14:06.
Working...
X