*! version 0.1.0 2013-12-06 | vanheuvelen long

* tpr: tpr_sim_dta_mergesave: combine data for each N to combed dataset

program define tpr_sim_dta_mergesave

    qui {
      foreach samplesize of numlist $sample_smallest $sample_sizes {
        if ($samplesize==$sample_smallest) use temp-$simdta-$samplesize, clear
        else append using temp-$simdta-$samplesize
      }
    }

    aorder
    order samplesize simiter OLstatus BRstatus GLstatus WAstatus LRstatus
    char _dta[experiment] `experiment'
    sort samplesize
    local dtatag = "$simdta.dta | $tag"
    label data "`dtatag'"
    note _dta: `dtatag'.
    qui compress
    datasignature set, reset
    save $simdta, replace

end
exit