SPSS Python Extension Functions 

The SPSS Python Extension is an addon to SPSS that allows you to include Python code in SPSS syntax programs, greatly enhancing the programmability of  SPSS. The Python extension is completely free, and is available directly from SPSS at:


Those interested in working with Python might also be available in the book "Programming and Data Management in SPSS," which gives a good introduction to using Python in SPSS. It is also free, and is available from the original author (Raynald Levesque) at:


So why should you be interested in Python? Well, basically, it gives you the ability to do a lot of new things in SPSS syntax, such as the following:

Taking advantage of the last capability, we have created a number of useful Python functions that you might want to use in your own programs. You will need to have the Python extension installed in order to use them, but after that, all you'd need to do is include the function syntax in your program with an INSERT FILE command and you'll be able to use the function. If you have created a Python function yourself and would like to make it available to others through this website, or if you ever think you have found an error in one of functions we provide here, please send us an email at stat.help.questions@gmail.com .

Functions Related to Mplus

Function name Last Revision Description
MplusCFA2013-09-14Performs a confirmatory factor analysis within SPSS by using Mplus. The program automatically converts the active dataset to Mplus, writes the necessary Mplus code, runs the analysis in Mplus, and then brings the results into the SPSS output window.
MplusMItoSPSS 2012-07-13 Reads in a set of multiple imputation datasets generated in Mplus and turns them into a multiple imputation dataset in SPSS.
MplusPathAnalysis2016-07-30Performs a path analysis within SPSS by using Mplus. The program automatically converts the active dataset to Mplus, writes the necessary Mplus code, runs the analysis in Mplus, and then brings the results into the SPSS output window.
MplusTwoLevel2015-05-18Runs a two-level model from within SPSS by using Mplus. The program automatically converts the active dataset to Mplus, writes the necessary Mplus code, runs the analysis in Mplus, and then brings the results into the SPSS output window.
MplusWiths2013-09-06Writes a set of "with" statements in the Output window that can be copied into an Mplus program. The program can either intercorrelate all of the items within a list, or it can correlate the items in one list with all of the items in a second list.
runMplusDeltaR22013-06-23Given a base Mplus input file, this progrm will write and run a collection of additional Mplus input files that each drop one predictor from the model. These can be used to determine the delta R2 for each of the predictors in the model.
analyzeMplusDeltaR22013-06-23This program takes the output from the rnMplusDeltaR2 program, automatically calculates the delta R2 for each predictor, and puts the results in an SPSS data set.
SPSStoMplus 2014-03-13 Converts an SPSS data set into Mplus format, and also generates a skeleton input file that would read the data set.. It performs a number of transformations to the data to make it consistent with the requirements of Mplus.

Other Functions

Function name Last Revision Description
artCategorize2014-11-30Artificially categorizes a continuous variable. You give the name of the variable and the number of groups, and the function will find the appropriate percentiles and create a new variable that divides people into groups based on their scores on the continuous variable.
condSelect2012-08-23Allows you to randomly select a fixed number of participants from each level of a grouping variable. This is useful when you want to graphically examine relations but there are too many participants to make sense of the graphs.
dBetween2013-04-04Calculates the d for a single two-group between-subjects comparison.
dBetweenDataset2013-04-26Calculates the results for two-group between subjects comparisons and puts them into a new dataset. Allows you to optionally define multiple groupings, multiple outcomes, and a split variable.
descriptive 2010-06-21 Allows you to use a summary statistic, like the mean, standard deviation, or median, as part of a formula so that it automatically updates when the data changes.
descriptiveDataset2013-09-11Calculates one or more summary statistics for one or more variables and puts the results into a new data set. Also allows you to optionally define a split variable.
dummycode 2012-09-07 Automatically creates a set of dummy codes for a categorical variable.
ExcelToSPSS2014-03-19Locates all of the Excel files (either .xls or .xlsx) in a source directory and converts them all to SPSS data sets, which are placed in an identified target directory.
ICC2014-11-19Calculates the intraclass correlation and the design effect for a cluster variable on a list of outcomes.
mergeAllSPSScases2015-07-26Locates all of the SPSS data sets in a source directory and merges them into a single file, which is placed in an identified target directory. Specifically used to merge datasets that have a similar set of variables but different cases.
nameSplit 2014-08-31 Given a long filename, it returns it automatically split into smaller portions so that it doesn't violate SPSS constraints on how many characters are allowed on a single line of syntax.
numericMissing2013-08-27Sets the missing values for all numeric variables in the data set using a single command.
resolveDuplicates2015-09-21Resolves duplicate cases in a dataset. You specificy a primary row for each case, which is where most of the values are taken from. However, if the primary row is missing a value on the variable, it is filled in from the other rows for that case if they have valid values.
textSplit2014-02-17Reads a text variable and then creates a number of additional variables separating the contents of the original text variable into different parts based on an identified delimiter. This can be used to take a sentence and have each word put in a different variable.
varMode2015-01-07SPSS Python Extension function to calculate the mode of a set of variables.
weightedCorr2013-10-15Creates a correlation matrix using a regression weight. This function calculates each weighted correlation individually using the regression command (rather than using the WEIGHT command, which artificially increases your sample size), and then combines them into a  correlation matrix.
withinDescriptive2012-12-02Similar to the descriptive function, this allows you to use a summary statistic as part of a formula. However, this function restricts the calculation to those cases that are in the same condition as the current case on a split variable.

Back to the Stat-Help.com home page.