-
Notifications
You must be signed in to change notification settings - Fork 3
/
byablesvymean.ado
46 lines (36 loc) · 1.13 KB
/
byablesvymean.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
program define byablesvymean, byable(recall)
// svy mean can not be used with by. This program executes svy over the different categories of the by variable (right now, can use only one variable in the by list)
syntax varlist [if] [using], [replace]
marksample touse
// Prepare the file for saving, if applicable
if (`"`using'"'~="") {
// get the filename
di `""using" option was specified"'
di `"regexm:"'
di regexm(`"`using'"',`"((.*)\.(.+))$"')
if (regexm(`"`using'"',`"((.*)\.(.+))$"')) {
local pathtofile_original = regexs(1)
local pathtofile_withoutextension = regexs(2)
local pathtofile_extension = regexs(3)
}
di `"pathtofile_original:`pathtofile_original'"'
di `"pathtofile_withoutextension:`pathtofile_withoutextension'"'
di `"pathtofile_extension:`pathtofile_extension'"'
}
else {
di `"using option NOT specified"'
}
if _by() {
di "_by() is true"
// count if `touse'
svy: mean `varlist' if `touse'
tempname M themean
matrix `M' = r(table)
local `themean' = `M'[1,1]
di "themean = ``themean''"
}
else {
di "Use this command with 'by'"
exit
}
end program