Announcement

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

  • Generate vs Replace

    Is there any particular reason why encode requires the result to be placed into a new variable:

    Code:
     encode varname [if] [in] , generate(newvar) [label(name) noextend]
    while destring gives the user a choice between generating and replacing??

    Code:
    destring [varlist] , {generate(newvarlist)|replace} [destring_options]
    Is it because encode supports if- and in-modifiers, while destring doesn't? Since encode is commonly used on the whole variable, would be good if it could replace without generating a new variable when the modifiers are not specified.

    Thank you.


  • #2
    I can speak for destring to the extent that I was the original author, destring arose because students I was teaching would often write text headers with metadata in the first few observations in the then new Data Editor. Then as now text in the first observation that was not numeric led the Editor to create a new variable as string in the very first instance. For variables that you want to be numeric that was wrong and not quite trivial for students to reverse safely. So the very first versions of destring replaced variables that were string as numeric and replacing was the only mode, This can be seen from the first public version (1997) in https://www.stata.com/products/stb/journals/stb37.pdf Later the scope to generate was added. In fact the command was rewritten very drastically on adoption in Stata 7,

    encode was born an official command much earlier and shows more signs of a Unix philosophy of doing just one thing well, To Stata 16 for example, encode can still only work on one variable at a time,

    Comment


    • #3
      Dear Nick, thank you very much for the story of destring. This was a rather arbitrary comparison: recode is an internal (built-in) command so should follow all the StataCorp's philosophy, yet it implements both the generate and replace behaviors.

      Comment


      • #4
        FWIW, recode is neither built-in (as opposed to ado) nor did it originate from StataCorp. The manual acknowledges

        This version of recode was written by Jeroen Weesie of the Department of Sociology at Utrecht
        University, The Netherlands.
        Best
        Daniel

        Comment


        • #5
          recode was born as an official command. Then Jeroen rewrote it and his version was folded back promptly into Stata.

          Sooner or later encode is likely to be rewritten and then this kind of anomaly will be removed..

          Comment

          Working...
          X