Hi Statalist,

I'm struggling to generate the descriptive statistics for my dataset. Here is the example of my data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ID str1 Sex str4 ICD float Cost
 1 "1" "A181"  41578.27
 1 "1" "A181"  2506.016
 2 "1" "A181" 1108.8945
 3 "2" "A181" 1622.8583
 4 "1" "A181" 10756.528
 5 "2" "A181" 1108.8945
 5 "2" "A181" 1110.9061
 6 "1" "A181"  2867.536
 7 "1" "A181"  530.5595
 7 "1" "A181"  9054.715
 7 "1" "A181"   5533.85
 8 "2" "A182" 1145.6062
 8 "2" "A182"  21381.66
 9 "2" "A182" 1145.6062
10 "2" "A182"  4148.777
11 "2" "A182"  25998.42
11 "2" "A182"  4132.329
11 "2" "A182"  5367.452
11 "2" "A182"  5790.894
11 "2" "A182"  6500.989
12 "2" "A182"  7535.454
13 "1" "A182" 1145.6062
13 "1" "A182" 1145.6062
13 "1" "A182"  5161.263
13 "1" "A182" 1145.6062
13 "1" "A182"  2517.015
13 "1" "A182"  2517.015
14 "1" "A183" 1019.3783
15 "2" "A183" 1145.6062
16 "1" "A183" 1682.2006
16 "1" "A183" 11127.165
17 "1" "A183"  1293.459
17 "1" "A183"  921.8157
17 "1" "A183"  4948.536
18 "2" "A183"  4948.536
19 "1" "A183" 1682.2006
19 "1" "A183"  4970.664
20 "2" "A183" 1145.6062
21 "1" "A183" 11212.156
21 "1" "A183" 1235.6254
21 "1" "A183"  39530.45
21 "1" "A183"  921.8157
22 "1" "A183"  10305.93
22 "1" "A183"  4948.536
23 "1" "A183"  4948.536
24 "2" "A184"  17459.18
24 "2" "A184"   6081.57
25 "1" "A184" 1368.8938
26 "2" "A184" 1532.8392
27 "1" "A184" 17041.771
28 "2" "A184" 1532.8392
29 "1" "A184"  1293.459
30 "2" "A184"  5954.839
31 "2" "A185" 1989.9753
32 "1" "A185"  9376.067
33 "1" "A185"  10502.16
33 "1" "A185"  297.2139
33 "1" "A185" 11327.823
33 "1" "A185" 1081.7379
33 "1" "A185"  38024.01
34 "1" "A185"  3589.197
35 "1" "A185" 1466.9594
36 "1" "A185"  23008.18
36 "1" "A185" 2155.4797
36 "1" "A185" 1872.2968
37 "1" "A185" 13298.687
38 "1" "A185" 1012.8406
39 "2" "A185"  782.5124
40 "1" "A185" 1090.2872
41 "2" "A185"  2473.262
end
The result i want to generate is the Total cost and average cost per patient by ICD and by Sex. Something that looks like this:
Total cost Cost per patient
Sex =1 Sex = 2 Sex =1 Sex =2
ICD = A181
A182
A183
A184
A185

Could you kindly show me how to do this? Thank you so much