help mata tostack()
help mata enter()
help mata swapst()
help mata rotst()


Commands to manipulate the internal stack set up by rpnfcn()


Command name Argument

&tostack() x

&enter() NULL

&swapst() NULL

&rotst() NULL


These functions are used to place matrices into the appropriate places in the stack used by rpnfcn(). &tostack() places the matrix x in a new top element of the stack. &enter() copies the current top element of the stack to a new top element in the stack. &swapst() swaps the two top elements of the stack. &rotst() rotates the stack one step down, meaning that the bottom-most element becomes the top element, while all others are shifted one step down.


The commands &tostack() and &enter() both copies the indicated matrix, and for very large matrices the user must thus ensure that Stata has sufficient memory to execute the command. The commands &swapst() and &rotst() on the other hand do not move or copy matrices as such, but rather rearranges their labels (the pointers in the stack) so as to create the desired effect.

Source code



Henrik StÝvring, Research Unit of General Practice, University of Southern Denmark. Please email if you have comments, questions or observe any problems.

Also see

Manual: [M] Mata Reference Manual

Online: help for [M-0] mata, Evaluation of algorithm matrix using RPN, RPN binary operators, RPN distribution functions, RPN functions for integration