Announcement

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

  • Drop observations in a string variable

    Hello Everyone, i'm a new user of Stata and having trouble with a really simple command. I can't seem to delete observation with a string variable. Can someone help me.
    Thanks


    AJCC |
    Clinical N | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 478,848 64.58 64.58
    1 | 1,625 0.22 64.80
    X | 260,978 35.20 99.99
    88 | 61 0.01 100.00
    ------------+-----------------------------------
    Total | 741,512 100.00

    . drop if (TNM_CLIN_N =="1")
    (0 observations deleted)


  • #2
    Looks like you probably have a numeric variable with labels. try:
    Code:
    tab TNM_CLIN_N, nol
    and see.

    Comment


    • #3
      It's not obvious that TNM_CLIN_N has any relation at all to a variable with label "AJCC Clinical N".

      TNM_CLIN_N is evidently a string variable, but it can not be what you are tabulating as otherwise 1625 observations would have been dropped.

      In any case, there is a radical confusion of categories here. Observations can't have string variables. Perhaps what you mean is that you want to drop observations for which there is either

      (a) entirely non-numeric characters in a string variable

      or

      (b) a value label with non-numeric characters for a numeric variable.

      We can't tell. You must tell us more.

      Comment


      • #4
        Thanks for reply
        The variable name is TNM_CLIN_N and it's labeled AJCC Clinical N.
        The type is str4 and Format is %4s

        When I tab the variable the categories are 0 - 1 - X - 88

        I want to drop all the observation that have either "1" or "88"

        is this clearer?

        thanks again

        Comment


        • #5
          If what you say is true then

          Code:
           
          drop if (TNM_CLIN_N =="1")
          should not do what you report, namely drop nothing.

          There may be leading or trailing spaces. See what happens with

          Code:
          replace TNM_CLIN_N = trim(TNM_CLIN_N)

          Comment


          • #6
            One explanation is that your values include spaces. For example

            Code:
            clear
            input str4 TNM_CLIN_N
            " 0"
            " 1"
            x
            88
            end
            label var TNM_CLIN_N "AJCC Clinical N"
            tab TNM_CLIN_N
            drop if TNM_CLIN_N == "1"
            drop if trim(TNM_CLIN_N) == "1"

            Comment


            • #7
              It worked!

              thank you very much guys

              Comment

              Working...
              X