-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicstat.ado
More file actions
142 lines (111 loc) · 3 KB
/
basicstat.ado
File metadata and controls
142 lines (111 loc) · 3 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
**! version 1.0.1 Arman Mahmud, 21aug2025
cap program drop basicstat
program define basicstat
syntax using, [EXClude(string)]
** using dataset
*~~~~~~~~~~~~~~~~~~~~~~~*
u `using', clear
** type "string"
*~~~~~~~~~~~~~~~~~~~~~~~*
qui ds, has(type string)
loc string_var_all = "`r(varlist)'"
if "`exclude'" != "" {
loc exc = "`exclude'"
foreach x of loc string_var_all{
loc found = 0
foreach y of loc exc{
if "`x'" == "`y'"{
loc found = 1
}
}
if `found' == 0{
loc string_final = "`string_final' `x'"
}
}
}
if "`exclude'" == "" {
loc string_final = "`string_var_all'"
}
foreach x of loc string_final {
qui {
n di as input "Analysis running for `x' (string)"
preserve
contract `x'
ren _freq frequency
export excel using "basicstat_string_output.xlsx", firstrow(var) sheet(`x') sheetmodify
n di as result "Analysis completed for `x'"
restore
}
}
** type "non string"
*~~~~~~~~~~~~~~~~~~~~~~~*
qui ds, not(type string)
loc num_var_all = "`r(varlist)'"
if "`exclude'" != "" {
loc exc = "`exclude'"
foreach x of loc num_var_all{
loc found = 0
foreach y of loc exc{
if "`x'" == "`y'"{
loc found = 1
}
}
if `found' == 0{
loc num_final = "`num_final' `x'"
}
}
}
if "`exclude'" == "" {
loc num_final = "`num_var_all'"
}
putexcel set "basicstat_numeric_output.xlsx", modify
loc j = 2
foreach x of local num_final{
qui {
n di as input "Analysis running for `x' (numeric)"
count if !missing(`x')
if `r(N)' > 0 {
sum `x', detail
putexcel A1 = ("Var_Name")
putexcel B1 = ("Obs_No")
putexcel C1 = ("Mean")
putexcel D1 = ("Sd")
putexcel E1 = ("Skewness")
putexcel F1 = ("Kurtosis")
putexcel G1 = ("Min")
putexcel H1 = ("Max")
putexcel I1 = ("p25")
putexcel J1 = ("p50")
putexcel K1 = ("p75")
putexcel A`j' = ("`x'")
putexcel B`j' = (`r(N)')
putexcel C`j' = (`r(mean)')
putexcel D`j' = (`r(sd)')
putexcel E`j' = (`r(skewness)')
putexcel F`j' = (`r(kurtosis)')
putexcel G`j' = (`r(min)')
putexcel H`j' = (`r(max)')
putexcel I`j' = (`r(p25)')
putexcel J`j' = (`r(p50)')
putexcel K`j' = (`r(p75)')
loc j = `j' + 1
}
n di as result "Analysis completed for `x'"
}
}
** notes
*~~~~~~~~~~~~~~~~~~~~~~~*
n di ""
n di ""
n di as result "{hline}"
n di as result " ✨ Analysis Complete! ✨"
n di as result "{hline}"
n di ""
n di as result " Output files have been saved to the current working directory."
n di ""
di as result `" String variable summary: {browse "basicstat_string_output.xlsx"}"'
di as result `" Numeric variable summary: {browse "basicstat_numeric_output.xlsx"}"'
n di ""
n di as result " You can find the directory path by typing " as input "pwd" as result " in the Command window."
n di as result "{hline}"
end