Announcement

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

  • encode foreach error

    I am trying to encode multiple variables and replace remaining strings with a numeric character - however i am getting an error r(100)


    . foreach var of varlist company_23 debt_23 pairincome {
    2. encode `var', gen(_`var')
    3. replace `var'=0 if `var>2500
    }
    varlist required
    r(100);

    How can i solve this?

  • #2
    You should probably rethink your approach. enocde sorts string values alpha-numerically and then assigns numeric values 1, 2, ... Therefore, the numeric codes will have different labels for different variables. I am not even sure whether your original variables are strings or numeric values that just happen to be stored as strings. In the latter case, you want destring (or real()). Note that you cannot mix string values and numeric values in one variable.

    Comment


    • #3
      Thank you! Yes that makes sense I used destring!

      Comment

      Working...
      X