Announcement

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

  • #16
    Originally posted by Andrew Musau View Post
    You just need the one variable.

    Code:
    dataex SystolicBP if missing(real(SystolicBP))
    dataex SystolicBP if missing(real(SystolicBP))

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str4 SystolicBP
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    ""
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 53146 observations
    Use the count() option to list more


    If what you are trying to achieve is to filter out the entries that have the characters, there is a way I get that. Let me know if that is what you are driving at.

    Comment


    • #17
      If what you are trying to achieve is to filter out the entries that have the characters, there is a way I get that. Let me know if that is what you are driving at.
      Yes, that is what is needed. You can keep a couple and then use dataex to extract them and post here.

      Comment


      • #18
        Originally posted by Andrew Musau View Post

        Yes, that is what is needed. You can keep a couple and then use dataex to extract them and post here.
        list SystolicBP if !missing(SystolicBP) & missing(real(SystolicBP)), noobs

        +----------+
        | Systol~P |
        |----------|
        | 120` |
        | 130- |
        | `100 |
        | 120- |
        | 100` |
        |----------|
        | 10-0 |
        | `130 |
        | - |
        | `120 |
        | 101` |
        |----------|
        | `90 |
        | `117 |
        +----------+



        . dataex SystolicBP if !missing(SystolicBP) & missing(real(SystolicBP))

        ----------------------- copy starting from the next line -----------------------
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str4 SystolicBP
        "120`"
        "130-"
        "`100"
        "120-"
        "100`"
        "10-0"
        "`130"
        "-"   
        "`120"
        "101`"
        "`90" 
        "`117"
        end
        ------------------ copy up to and including the previous line ------------------

        Listed 12 out of 53146 observations

        Comment


        • #19
          The grave accent is used in local macros, so that is why destring has problems if you include it within -ignore-. I will look into this, but the following should work:

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str4 SystolicBP
          "120`"
          "130-"
          "`100"
          "120-"
          "100`"
          "10-0"
          "`130"
          "-"  
          "`120"
          "101`"
          "`90"
          "`117"
          end
          
          gen wanted= real(ustrregexra(SystolicBP, "[^\d]+", ""))
          Res.:

          Code:
          . l, sep(0)
          
               +-------------------+
               | Systol~P   wanted |
               |-------------------|
            1. |     120`      120 |
            2. |     130-      130 |
            3. |     `100      100 |
            4. |     120-      120 |
            5. |     100`      100 |
            6. |     10-0      100 |
            7. |     `130      130 |
            8. |        -        . |
            9. |     `120      120 |
           10. |     101`      101 |
           11. |      `90       90 |
           12. |     `117      117 |
               +-------------------+
          Last edited by Andrew Musau; 13 Jun 2021, 17:05.

          Comment


          • #20
            Thanks for this. Unfortunately it is a bit confusing for me as I am pretty new to Stata. Would appreciate some breakdown.

            Comment


            • #21
              gen wanted= real(ustrregexra(SystolicBP, "[^\d]+", ""))
              The -real- function converts a string to a numeric variable with values either being numbers or missing (only number strings can be converted to real numbers). See

              Code:
              help real()
              The rest is just deleting all nonnumeric characters in your variable and then passing the result through the -real- function. See a combination of the ICU Regular Expressions Manual and the -ustrregexra- function to gain a deeper understanding.

              Code:
              help ustrregexra()
              Last edited by Andrew Musau; 13 Jun 2021, 17:46.

              Comment


              • #22
                So I have another string related question and I'm wondering if it is ok to post here or start another post? I do not really know what the rules are around that. Someone please help me. Thanks

                Comment


                • #23
                  It would be best to start a new post, with a title that describes your new question. Members often decide whether or not they are going to follow a topic, and members who have decided not to follow this topic may not see your new question if you post it here.

                  Comment


                  • #24
                    Originally posted by William Lisowski View Post
                    It would be best to start a new post, with a title that describes your new question. Members often decide whether or not they are going to follow a topic, and members who have decided not to follow this topic may not see your new question if you post it here.
                    Thanks. This is helpful. I will start a new post.

                    Comment

                    Working...
                    X