Announcement

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

  • Keeping selected values of a variable

    One of a variable in my dataset contains many values and I would like to keep 30 values out of more than 500 using Stata 13. The variable is in string format so I tried to use the keep if inlist(variable, x1, x2,..) but Stata returned a message that the list is long. In this forum, I found an egen command option but it requires numeric values. Please help and thank you in advance.

  • #2
    See https://www.statalist.org/forums/for...ssion-too-long. If these are numerical values stored as string, nothing stops you from creating a numerical variable and using this with -inlist()- or using the -real()- function.

    Code:
    destring var1, gen(var2)
    keep if inlist(var2, ...)
    or

    Code:
    keep if inlist(real(var1), ...)

    Comment


    • #3
      Andrew,
      Thank you. I followed the link you provided. The inlist2 worked fine for me.

      Comment


      • #4
        https://www.stata.com/support/faqs/d...s-for-subsets/ explains a different approach that is often appropriate.

        Comment

        Working...
        X