*! version 1.1.6 20feb2024

Title

lppinv -- a non-iterated general implementation of the LPLS
estimator for cOLS, TM, and custom cases

Syntax

lppinv
varlist|matname (rowsums first for TM problems)
[if] [in]
[, options]

Type of the LP problem
cols OLS constrained in values (cOLS)
(see Description)

tm Transaction Matrix (TM), options cols and tm
are mutually exclusive (not specifying any of them equals custom)

Constructing the LHS
model(varlist|matname) the MODEL part of `a`, including an
eventual user-provided constant as a variable|matrix column in cOLS
(see Methods and formulas)

constraints(varlist|matname) the CONSTRAINTS part of `a`

slackvars(varlist|matname) the SLACK/SURPLUS VARIABLES part of
`a`

zerodiagonal set all the diagonal elements of `a` to 0

SVD-based estimation
tolerance(real) roundoff error,
a number to determine when a number is small enough to be considered
zero (optional, not specifying tol is equivalent to specifying
tol=0)

level(#) confidence level (by default: c(level))

Monte-Carlo-based t-test
seed(#) random-number seed, # is any number between 0 and
2^31-1 (or 2,147,483,647)
(by default: c(rngseed_mt64s))

iterate(#) number of iterations, # must be divisible
by 50 (by default: c(maxiter))

distribution(string) random-variable generating function, name
of an earlier declared Mata object returning a
real matrix (r x c) with two arguments, real scalars r and
c (by default: lppinv_runiform, see
Examples on how to pass rnormal() to
lppinv, the full list of built-in functions is available
here)

nomc skip the Monte Carlo-based t-test

notrace hide any output with the exception of dots

depvar and indepvars may contain time-series operators if data are
tsset; see tsvarlist.

by, collect, fp, rolling, statsby, and xi
are allowed; see prefix.

weights are not allowed; see weights.

See [R] regress postestimation for features
available after estimation.

Description

The program implements the LPLS (linear programming through least squares)
estimator with the help of the Moore-Penrose inverse (pseudoinverse), calculated
using singular value decomposition (SVD), with emphasis on the
estimation of OLS constrained in values (cOLS), Transaction Matrix
(TM), and custom (user-defined) cases. The pseudoinverse offers a
unique minimum-norm least-squares solution, which is the best linear unbiased
estimator (BLUE); see Albert (1972, Chapter VI). (Over)determined problems are
accompanied by regression analysis, which is feasible in their
case. For such and especially all remaining cases, a Monte Carlo-based
t-test of mean NRMSE (normalized by the standard deviation of
the RHS) is performed, the sample being drawn from a uniform or user-provided
distribution (via a Mata function).

OLS constrained in values (cOLS) is an estimation based on constraints in
the model and/or data but not in parameters. Typically, such models are of size
≤ kN, where N is the number of observations, since the number of their
constraints may vary in the LHS (e.g., level, derivatives, etc.).

Example of a cOLS problem:

Estimate the trend and the cyclical component of a country's GDP
given the textbook or any other definition of its peaks, troughs, and
saddles. For a pre-LPLS approach to this problem, see (Bolotov, 2014).

Transaction Matrix (TM) of size (M x N) is a formal model of
interaction (allocation, assignment, etc.) between M and N elements
in any imaginable system, such as intercompany transactions (netting tables),
industries within/between economies (input-output tables), cross-border
trade/investment (trade/investment matrices), etc., where row and
column sums are known, but individual elements of the TM may not be:

• a netting table is a type of TM
where M = N and the elements are subsidiaries of a MNC;

• an input-output table (IOT) is a type of TM
where M = N and the elements are industries;

• a matrix of trade/investment is a type of TM
where M = N and the elements are countries or (macro)regions, where
diagonal elements may be equal to zero;

• a country-product matrix is a type of TM where
M ≠ N and the elements are of different types;

...

Example of a TM problem:

Estimate the matrix of trade/investment with/without zero diagonal
elements, the country shares in which are unknown. For a pre-LPLS approach
to this problem, see (Bolotov, 2015).

lppinv returns matrix r(solution), scalar r(nrmse), scalar
r(r2_c) (R-squared for CONSTRAINTS in TM), and regression and/or
t-test results. In addition, matrix r(a) is available with
the help of the command:
. return list, all.

Methods and formulas

The LP problem in the LPLS estimator is a matrix equation `a @ x = b`,
loosely based on the structure of the Simplex tableau, where `a` consists
of coefficients for CONSTRAINTS, LP-type CHARACTERISTIC and/or SPECIFIC, and
for SLACK/SURPLUS VARIABLES (the upper part) as well as for the MODEL (the lower
part), as illustrated in Figure 1. Each part of `a` can be omitted to
accommodate a particular case:

• cOLS problems require SPECIFIC CONSTRAINTS, no
LP-type CHARACTERISTIC CONSTRAINTS, and a MODEL;

• TM requires LP-type CHARACTERISTIC CONSTRAINTS,
no SPECIFIC CONSTRAINTS, and an optional MODEL;

• SLACK/SURPLUS VARIABLES are included only for inequality
constraints and should be set to 1 or -1;

...

Figure 1: Matrix equation `a @ x = b`

`a`
| `b`

+–––––––––––––––––––––––––––––––––––––––+–––––––––––––––––+–––––––––––––+

| CONSTRAINTS: CHARACTERISTIC/SPECIFIC
| SL/SU VARIABLES | CONSTRAINTS |

+–––––––––––––––––––––––––––––––––––––––+–––––––––––––––––+–––––––––––––+

| MODEL
| MODEL |

+–––––––––––––––––––––––––––––––––––––––––––––––––––––––––+–––––––––––––+

Source: self-prepared

The solution to the equation, `x = pinv(a) @ b`, is estimated with the
help of SVD and is a minimum-norm least-squares
generalized solution if the rank of `a` is not full. To check if
`a` is within the computational limits, its (maximum) dimensions can be
calculated using the formulas:

• (k * N) x (K + K*) cOLS without
slack/surplus variables;

• (k * N) x (K + K* + l) cOLS with
slack/surplus variables;

• (M + N) x (M * N) TM without
slack/surplus variables;

• (M + N) x (M * N + l) TM with
slack/surplus variables;

• M x N custom without
slack/surplus variables;

• M x (N + l) custom with
slack/surplus variables;

where, in cOLS problems, K is the number of independent variables in
the model (including the constant), K* is the number of eventual extra
variables in CONSTRAINTS, and N is the number of observations; in TM,
M and N are the dimensions of the matrix; and in custom cases,
M and N or M x (N + l) are the dimensions of `a`.

Remarks

For Python-savvy users, there is a Python version of lppinv
https://pypi.org/project/lppinv/ with equivalent functionality.

Examples

cOLS problem:
. sysuse gnp96.dta, clear
. gen correction = runiform()
. lppinv gnp96, cols m(time) c(d.gnp96) s(correction)
. matlist r(solution)

TM problem with Monte Carlo t-test based on the uniform distribution:
. clear
. set obs 30
. gen rowsum = rnormal(15, 100)
. gen colsum = rnormal(12, 196)
. lppinv rowsum colsum, tm level(90)
. lppinv rowsum colsum, tm zerod level(90)
. matlist r(solution)

TM problem with Monte Carlo t-test based on the normal distribution:
...
. mata: function lppinv_normal(r, c) return(rnormal(r,c, 0, 1))
. lppinv rowsum colsum, tm level(90) dist(lppinv_normal)
. matlist r(solution)

Author

Ilya Bolotov

Prague University of Economics and Business

Prague, Czech Republic

ilya.bolotov@vse.cz

Thanks for citing this software and my works on the topic:

Bolotov, I. (2024). 'LPPINV': module providing a non-iterated general
implementation of the LPLS estimator for cOLS, TM, and custom cases. Available
from https://ideas.repec.org/c/boc/bocode/s459045.html.

References

Albert, A., 1972. Regression And The Moore-Penrose Pseudoinverse. New
York: Academic Press.

Bolotov, I. 2014. Modeling of Time Series Cyclical Component on a Defined
Set of Stationary Points and its Application on the US Business
Cycle. [Paper presentation]. The 8th International Days of Statistics and
Economics: Prague.
https://msed.vse.cz/msed_2014/article/348-Bolotov-Ilya-paper.pdf

Bolotov, I. 2015. Modeling Bilateral Flows in Economics by Means of Exact
Mathematical Methods. [Paper presentation]. The 9th International Days of
Statistics and Economics: Prague.
https://msed.vse.cz/msed_2015/article/111-Bolotov-Ilya-paper.pdf

PS Please also check the Web of Science (WoS) for new research on LPLS.