-------------------------------------------------------------------------------
help for insob
-------------------------------------------------------------------------------

Insert empty observations

insob nobs pos [, after ]

Description

insob inserts nobs empty observations before observation number pos.

Options

after When the option "after" is specified, the empty observations are inserted after observation number pos (in stead of before).

Remarks

The program works by adding a local variable that fixes the original sort order. After new observations have been added, the relative sort order of pre-existing observations is restored with empty observations before (after) observation number pos. This approach can be relatively slow for large data files.

Examples

. insob 1 1 // Inserts one observation at beginning of the dataset

. insob 2 _N, after // Inserts two observations at end of the dataset

Hint: insob can be used to create custom LaTeX tables (assuming existing commands like tabstat, est2tex, or textab are not what you are looking for). The following example suggests a procedure to export a matrix mtest containing four columns as a LaTeX table.

. drop _all

. svmat mtest

. tostring mtest1 mtest2 mtest3 mtest4, replace force format(%9.2f)

. insob 1 1 // Add row headers

. replace mtest1 = "$ V_1 $" in 1

. replace mtest2 = "$ V_2 $" in 1

. replace mtest3 = "$ V_3 $" in 1

. replace mtest4 = "$ V_4 $" in 1

. gen a = "&" // Column separator

. gen e = " \\\\" // End of row

. // Add tabular environment for use with the LaTeX-package booktabs

. insob 2 1

. replace mtest1 = "\begin{tabular}{rrrr}" in 1

. replace mtest1 = "\toprule\addlinespace[\defaultaddspace]" in 2

. insob 1 4

. replace mtest1 = "\midrule\addlinespace[\defaultaddspace]" in 4

. insob 1 _N, after

. replace mtest1 = "\bottomrule" in l/l

. insob 1 _N, after

. replace mtest1 = "\end{tabular}" in l/l

. outfile mtest1 a mtest2 a mtest3 a mtest4 e using "testtable.tex", noquote replace wide

Author

Bas Straathof, ECIS, Eindhoven University of Technology. Email me if you observe any problems. Thanks to Nick Cox for substantial improvements.