Announcement

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

  • Changing values of a variable based on prior value

    Hi,

    I am using a claims dataset in order to identify procedures performed during inpatient admission. The dataset has both professional claims and facility claims. In order to prevent duplicate counting of claims, I am trying to first identify the professional claims and then only identify the facility claims if the patient does not have a professional claim for that admission date. I used a loop to create a variable (ercp_is) that identified professional claims based on a CPT code. I now want to replace the "0" values for a "1" if a professional claim was identified for that admission date. This would allow me to only create a facility claim if no professional claim exists for that patient on that admission date.

    An example of my data is shown below.

    . dataex id ercp_is admdate in 18301/18312

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id ercp_is) str9 admdate
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 0 "14-AUG-19"
    3842505 1 "14-AUG-19"
    3842505 1 "14-AUG-19"
    3842505 1 "14-AUG-19"
    end
    ------------------ copy up to and including the previous line ------------------

    I am struggling trying to figure out how to replace these values. Thank you in advance for help.


  • #2
    I'm not sure I understand what you are asking for. I'm confused about whether ercp_is == 1 indicates a professional claim or if ercp_is == 0 indicates a professional claim. I'm going to assume that a professional_claim is an observation with ercp_is == 1. If I have that right, another way to say what you want is that if, for a given id and admdate, there is any observation having ercp_is == 1, you want to change ercp_is to 1 for all observations for that id and admdate.

    If that is what you want:
    Code:
    by id admdate (ercp_is), sort: replace ercp_is = ercp_is[_N]
    If that's not correct, please post back with a new example that contains at least two or three different id's. At least one of those id's should have observations where you want to change ercp_is, and another one (or more) should have observations where you want to leave all the ercp_is values as they are. Also show what the desired results would look like.

    Comment


    • #3
      Clyde Schechter The code worked perfectly. Thank you. Sorry for being unclear.

      Anna

      Comment

      Working...
      X