Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: New versions of -sencode- and -sdecode- on SSC

From   "Roger B. Newson" <>
To   "" <>
Subject   st: New versions of -sencode- and -sdecode- on SSC
Date   Tue, 01 Oct 2013 11:12:53 +0100

Thanks once again to KIt Baum, new versions of the -sencode- and -sdecode- packages are now available for download from SSC. In Stata, use the -ssc- command to do this, or -adoupdate- if you already have old versions of these packages.

The -sencode- and -sdecode- packages are described as below on my website, and are "super" versions of -encode- and -decode-, respectively.

The new version of -sencode- is still in Stata Version 10, although, if run under Stata Version 13, it can encode the very long string values (includung -strL- values) allowed by Stata Version 13. It adds a new -noextend- option, which functions as the option of the same name for -encode-, but which may not be specified with the -manyto1- option of -sencode-, or with the -replace- suboption of the -label()- opyion of -sencode-.

The new version of -sdecode- has now been updated to Stata Version 13, which was necessary to enable the decoding of long string values (including -strL- values) allowed by Stata Version 13. However, users of Stata Versions 12, 11, 10, 9, 8 and 7 can still install the old Stata Versions 11, 10, 9 and 7 versions of -sdecode- from my website by typing, in Stata,

net from "";

and selecting the subdirectory for the most recent Stata version of -sdecode- compatible with their versions of Stata.

Best wishes


Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Web page:
Departmental Web page:

Opinions expressed are those of the author, not of the institution.

package sencode from

sencode: Encode a string variable non-alphanumerically into a numeric variable

sencode is an extended version of encode. It takes, as input, a string variable, and generates, as output, a numeric variable, with value labels corresponding to values of the string variable. The output numeric variable may replace the input string variable or be generated as a new variable. sencode orders the numeric values corresponding to string values in the sequential order of appearance in the input string variable in the data set, or in another order specified by the user, instead of ordering them in alphanumeric order of the string value, as encode does. The mapping from numeric code values to string labels may be one-to-one (coded in order of
      first appearance of the string value) or many-to-one (coded in each
observation by the position of that observation in the data set, or in the
      user-specified ordering).

      Author: Roger Newson
      Distribution-Date: 24september2013
      Stata-Version: 10

INSTALLATION FILES                                  (click here to install)
(click here to return to the previous screen)

package sdecode from

      'SDECODE': module to decode a numeric variable into a string variable


       sdecode (super decode) creates an output string variable with
      values from the input numeric variable varname, using labels if
      present and formats otherwise. The output string variable may
      either replace the input numeric variable or be generated as a
      new variable named newvar. Unlike decode, sdecode creates an
      output string variable containing the values of the input
      variable as output by the list command and other Stata output,
      instead of decoding all unlabelled input values to missing.
      sdecode is especially useful if a numeric variable has value
      labels for some values but not for others. msdecode is a
      multivariate version of sdecode, which inputs     a list of
      numeric variables and (optionally) a list of delimiters,     and
      creates a single string variable, containing the concatenated and
          decoded values of all the input variables, separated by the
        delimiters if provided.

      KW: data manipulation
      KW: string conversion
      KW: value labels

      Requires: Stata version 13.0

Author: Roger Newson, National Heart and Lung Institute, Imperial College London
      Support: email

      Distribution-Date: 20130930

INSTALLATION FILES                                  (click here to install)
(click here to return to the previous screen)
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index