Split numeric variables with integer values into new smaller numeric variables

If you want to use nsplit, then feel free to use Stata's command ssc install:

   ssc install nsplit, replace 

Disclaimer:  There is no warranty on this software either expressed or implied.  This program is released under the terms and conditions of GNU General Public License.


About nsplit

Programmer:  Dan Blanchette
The Carolina Population Center
The University of North Carolina
Chapel Hill, NC  USA

Date:  30Nov2004
Last updated:  02Dec2004

Split numeric variables with integer values into new smaller numeric variables.


nsplit [varname] [if exp] [in range] , digits(digit pattern in existing variable) [generate(newvarlist or stub)]



nsplit creates however many new numeric variables it takes to split a numeric variable into digit pattern.  If your existing numeric variable contains decimal values, then nsplit will only split the integer portion of the number.



digits(digit pattern in existing variable) describes the pattern in the existing numeric variable.  If it is a repeated pattern then you only need to supply the number of digits the new variables should contain.  For example:
    . nsplit id, digits(2)

for an ID variable with 6 digits is equivalent to:
    . nsplit id, digits(2 2 2)


generate(newvarlist or stub) states what you want the new variable names to be.  If only one name is listed than that will be the first characters of the new variable names:  stub1 stub2 etc.  If no new variable name is en the original variable name will be used as the stub.



 . nsplit id, digits(2 3)

 . list id*

 . nsplit date, digits(2) generate(month year)

 . list date month year
  date month year
  1294 12 94
  588 5 88



Many suggestions were implemented that were made by:
Nicholas J. Cox, University of Durham, U.K.


Also see

On-line:  split, mod(), int(), dexfcns

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme