Welcome to the Training on Data Processing with Stata by Anshuman Bhattacharjee DCO ODISHA contract , preserve,restore,collapse in Stata Day 1, Sessions II
Preserve a Dataset preserve preserves the data, guaranteeing that data will be restored after program termination. restore forces a restore of the data now. set max_preservemem , available only in Stata/MP, controls the maximum amount of memory preserve will use to store preserved datasets in memory. Once this limit is exceeded, preserve will store datasets on disk. Command preserve
contract contract replaces the dataset in memory with a new dataset consisting of all combinations of varlist that exist in the data and a new variable that contains the frequency of each combination .
contract
collapse collapse converts the dataset in memory into a dataset of means, sums, medians, etc. Command : - collapse clist [if] [in] [weight] [, options] clist must refer to numeric variables exclusively where clist is either [(stat)] varlist [ [(stat)] ... ] [(stat)] target_var=varname [target_var=varname ...] [ [(stat)] ...] or any combination of the varlist or target_var forms, and stat is one of