*! version 3.0 Fernando Rios-Avila September 2022
help f_rcspline

Title

f_rcspline - Module for the construction of restricted cubic spline for f_able

Syntax

Restricted cubic spline

f_rcspline
prefix
=
oldvar
[if] [in]
[, knots(numlist) nknots(#k) weight(varname) replace]

Description

f_rcspline creates new variables containing restricted cubic spline of an existing variable.
Restricted cubic splines are constructed in a similar way to mkspline.
When no weights are provided, knots are calculated using centile, however if weights are specified
the programm uses _pctile instead. This may case small differences with respect to mkspline.

As with mkspline, knot locations are based on Harrell's (2001) recommended
percentiles nknots(#k) or user-specified points (option knots(numlist)).

It will use prefix to create the necessary number of new variables to create the splines.
Each new variable will be named consecutively starting from 2.

Options

Options

nknots(numlist) It specifies the number of knots that are to be used for a
restricted cubic spline. This number must be between 3 and 7 unless the knot locations are specified using
knots().

knots(#k) It specifies the exact location of the knots to be used for a
restricted cubic spline.

weight(varname) it specifies a weight variable to be used internally
to determine the empirical distribution of oldvar, and determine the
location of the knots when using the option nk:nots(#k).

replace Request to replace the variables if they already exist in the dataset.

Examples

Perform a logistic regression of outcome against a restricted cubic spline
function of dosage with four knots chosen according to Harrell(2001) recommended percentiles

webuse mksp2, clear

f_rcspline dose = dosage, nknots(4)

logistic outcome dosage dose2 dose3

f_able dose2 dose3, auto

margins, dydx(dosage)

Reference

Harrell, F. E., Jr. 2001.
Regression Modeling Strategies: With Applications to Linear Models, Logistic Regression, and Survival Analysis.
New York: Springer.

Also see

Help: f_able, f_spline, mkspline,