Announcement

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

  • Checking for specific string values

    Dear Statlist community,

    Despite being a very simple question, I did not figure how to perform this command through my textbook or by reading previous topics by searching through this forum. If this has been discussed earlier, I would be very grateful if someone could redirect me.

    I have huge datasets where I want to check for groups of specific string-values in a specific variable. This can be done by "list in if variable == "value"", but this seems to be very ineffective, time-consuming, and computationally expensive. Also, in many instances, I want only to check if the value contains a set of letters at the beginning of the string value. An example can be that I want to check for whether the variable icd_10 in a certain dataset contains the value of C31 (but this can typically contain values of C310, C311, C312, etc - but I want to check C30 as a group).

    Kind regards,
    Haakon

  • #2
    An addition: Could the following command be a viable solution?

    count if substr(icd_10,1,3)=="C30"

    Comment


    • #3
      Stata has a great detail of direct support for working with ICD codes. I've never used them in my own work, but

      Code:
      search icd
      will point you to specific commands. My impression is that this kind of query, looking for subsets of codes, is a very common need and is likely to be well supported.

      Comment


      • #4
        Hi! Thanks for your quick reply! Unfortunately, I can't install extra addons due to institutional restrictions... In my case, I need to do this command for several other variables that are similar to ICD codes as well. Hope a solution to this will be supported in Stata soon..!

        Comment


        • #5
          No add-ons involved; these are official commands. If the search recommended in #3 didn't show you much, then the explanation may be that you don't have an up-to-date version of Stata and if so pleaae see https://www.statalist.org/forums/help#version for why you should tell us about that.

          Otherwise #2 is good technique and I can't tell you a way to make it faster.
          Last edited by Nick Cox; 04 Feb 2021, 08:51.

          Comment

          Working...
          X