*! outfix2 1.1.0 NJC 1 April 1999
*! Outfix version 1.0 Gero Lipsmeier/UniBi 1.04.99
program def outfix2
        version 6.0
        syntax varlist(min=1) [if] [in] using/ , /*
	*/ Cols(numlist asc int >0) [ Format ]
        tokenize `varlist'
        local nvars : word count `varlist'
        tokenize `cols'
        local ncols : word count `cols'
        if `nvars' != `ncols' {
                di in r "number of variables should match number of columns"
                exit 198
        }

        set more off

        local logfile : log
        if "`logfile'" != "" {
                di in bl _n "Note: log `logfile' suspended for -outfix2-"
                log close
        }

        tempfile outlog
        log using `outlog'

        tempvar order touse
        gen long `order' = _n
        mark `touse' `if' `in'
        sort `touse' `order'
        qui count if !`touse'

        local i = 1 + r(N)
        while `i' <= _N {
                local dicmd
                local j = 1
                while `j' <= `nvars' {
                        local cj : word `j' of `cols'
                        local vj : word `j' of `varlist'
			if "`format'" != "" { local fmt : format `vj' }
                        local dicmd "`dicmd' _col(`cj') `fmt' `vj'[`i']"
                        local j = `j' + 1
                }
                di `dicmd'
                local i = `i' + 1
        }

        log close
        copy `outlog' "`using'"
        set more on

        if "`logfile'" != "" {
                log using `logfile', append
                di in bl _n "Note: log `logfile' resumed after -outfix2-"
        }
end