Announcement

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

  • Stata to ignore replace command if variable missing.

    Hello All,

    I am trying to run a do-file which has 4000 replace commands to recode missing variables from certain number to '.'. The problem is the data-set does not contain all the variables and thus the do-file stops when the variable does not exist. Is there a way I can tell Stata to ignore the replace command for variables which do not exist instead of manually deleting the command? Example:

    replace ACTD2001 = . if (ACTD2001 <= -1 | ACTD2001 >= 85 )
    replace ACTD7590 = . if (ACTD7590 <= -1 | ACTD7590 >= 85 )
    replace ACTD9001 = . if (ACTD9001 <= -1 | ACTD9001 >= 85 )
    replace ADDPR2WK = . if (ADDPR2WK <= -1 | ADDPR2WK >= 85 )
    replace ADLSI2WK = . if (ADLSI2WK <= -1 | ADLSI2WK >= 94 )
    replace ADPB2WK = . if (ADPB2WK <= -1 | ADPB2WK >= 85 )
    replace ADPBAGE = . if (ADPBAGE <= -1 | ADPBAGE >= 985 )

    replace ADPBAGE = . if (ADPBAGE <= -1 | ADPBAGE >= 985 )
    variable ADPBAGE not found

    Instead of manually removing this command from the do-file, is there a way I can tell Stata to skip this command for variables which do not exist?



  • #2
    This thread might be helpful to you.
    Best regards,

    Marcos

    Comment


    • #3
      Thank you

      That is exactly what I was looking for.

      Comment

      Working...
      X