Announcement

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

  • Replace an observation as missing after it reaches a certain value

    Good afternoon,
    I am trying to replace the observation values of a variable with a missing values after it reaches a certain value. The variable is a dummy and I need to recode it as missing after it gets the value of 1. I've tried to use "replace" command with if clauses and stuff but I have not reached any solution.
    Do you have any hint?
    Thank you

  • #2
    I have a vague idea of what you want to do, but without seeing an example of your data structure, I can't suggest code. Please use -dataex- to show a small representative example of your data. (-ssc install dataex-, -help dataex- for simple instructions).

    Comment


    • #3
      Alessandro:
      quite strange indeed.
      However, you may want to try:
      Code:
      . set obs 10
      
      . g X=_n-_n in 1/5
      
      . replace X=_n-[_n-1] if X==.
      
      . replace X=. if X==1
      PS Crossed in the cyberspace with Clyde's reply.
      Kind regards,
      Carlo
      (Stata 18.0 SE)

      Comment

      Working...
      X