Announcement

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

  • Help with ICD 10 Codes

    HI everyone,

    Fairly new to Stata so still have a lot of learning to do. Hope I can explain this well enough that I can get some help. I'm working with ICD 10 codes and trying to code for VBAC using the 4 codes in quotes below. The codes are in one of 25 fields named "dx1", "dx2", "dx3"....."dx25". I essentially need Stata to search through all the dx columns to find one or more of the codes and then create a new variable called "i_VBAC." If "yes" then create i_VBAC=1. If the codes do not match any of the below, then i_VBAC=0. I have tried the code below (that someone gave me to try) and keep getting an error of "invalid syntax." Can anyone help or point me in a direction to go next? Thank you!


    gen i_VBAC = 0
    forvalues i = 1/25 {
    replace i_VBAC = 1 if regexm(dx`i', "O34219", "O3421", "O34311", "O34212")}

  • #2
    replace regexm by inlist

    Comment


    • #3
      Ok, tried this and got an error. I tried removing the bracket but also got an error.....

      cap drop i_VBAC
      gen i_VBAC=0
      forvalues i = 1/25 {
      replace i_VBAC = 1 if inlist(dx`i', "O3421", "O34219", "O34211")}

      Here was the error message:


      . cap drop i_VBAC

      . gen i_VBAC=0

      . forvalues i = 1/25 {
      2. replace i_VBAC = 1 if inlist(dx`i', "O3421", "O34219", "O34211")}
      invalid '}'
      r(198);

      Comment


      • #4
        the close brace must appear on a line by itself

        Comment


        • #5
          One thing worth noting: inlist() will generate your flag if the ICD-10 code in the diagnosis field is exactly equal to any item in the list. That is, the variable has to contain "O3421", "O34219", etc.

          I'm less familiar with regexm(). However I think that would have generated your flag if the codes started with anything in the list you specified. You'll need to decide which case is better.

          VBAC means vaginal birth after caesarean section. There may not be universal agreement on what set of codes properly identify this. Here's one possible issue with O3421: in 2022, it isn't a complete ICD-10 code. That is, in 2022, you should expect to see codes starting with O3421, which includes O34211, O34212, O34218, and O34219. Of course, in 2016, it seems that O3421 was a complete code by itself, so pay attention to what data years you have.

          In any case, if you aren't into writing regular expressions (which regexm() uses), then consider using the icd10 commands like I mentioned in your previous post. They enable you to designate ranges of codes.
          Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

          When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

          Comment


          • #6
            Thank you! Putting the bracket on a line by itself worked. Weiwen, I have tried using the ICD10 command but am still wading through that learning. I agree that the ICD-10 codes for VBAC are not clear. I have created a listing of codes that I think are accurate and have been reading papers and talking with others to narrow down a list of appropriate codes. thank you for the heads up!

            Comment

            Working...
            X