-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_combos.ado
executable file
·59 lines (42 loc) · 1.13 KB
/
all_combos.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/***
# Title
__all_combos__ --- create all combinations of non-missing values
## Syntax
__all_combos__ varlist
- - -
Options:
> varlist: a list of variable names
- - -
## Description
This command creates a dataset of all possible combinations of non-missing values in the variable list. It will destroy all other variables and observations. Should be used with preserve and restore commands.
## Example
set obs 3
gen sex = 1
replace sex = 2 if _n == 1
gen race = _n
all_combos sex race
***/
capture program drop all_combos
program all_combos
//Modified version of STATA fillin function. This version does not
//treat missing as a valid combination.
syntax varlist
tempfile tmp0 tmp1 tmp2
keep `varlist'
save `"`tmp0'"', replace
gen _tgs20190227 = 1 if _n == 1
keep _tgs20190227
drop if missing(_tgs20190227)
save `"`tmp1'"', replace
use `"`tmp0'"', clear
foreach var of varlist `varlist' {
use `"`tmp0'"', clear
keep `var'
duplicates drop
drop if missing(`var')
cross using `"`tmp1'"'
save `"`tmp1'"', replace
}
drop _tgs20190227
sort `varlist'
end