Announcement

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

  • bysort replace by serial replace from unexisting observation

    ---------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str50 serial str16(mps mps1) byte Append_Source str50 wbc str8 rbc str13 mps_100wbc str16 mps_500rbc str43 species str4 mps_2000rbc str18 datah byte dups float sort1
    "158104" "negative" "negative" 1 "4.8" "0.93" "" "" "" "" "paeds_MalariaSlide" 0 2
    end
    label values Append_Source _append
    label def _append 1 "Appended dataset 1", modify
    ------------------ copy up to and including the previous line ------------------


    Dear all ,
    I am trying to replace all observation by second observation of wbc if serial is duplicated.The funny thing I have noted is that if there is only a single serial for example serial 158104 in my case, wbc is being replaced with a non-existing observation. In my case (serial 158104) the value of wbc=4.8.
    when I do the below code, it is being replaced by missing.As if the serial is duplicated with second observation of wbc as missing.

    by serial:replace wbc=wbc[2]

    Is this a stata 17 bug or am I not getting something correct?
    regards,
    Fred Orwa





  • #2
    See

    Code:
    help subscripting
    Same logic with the first observation being replaced by a missing value if you have

    generate xlag = x[_n-1]
    In this instance, x[_n-1]= x[0] which does not exist (or is not observed). You therefore need to specify an appropriate -if- condition, e.g.,

    Code:
    by serial:replace wbc=wbc[2] if _N==2

    Comment

    Working...
    X