I had asked this follow up in a previous thread but thought I would post again in a new topic:
I have panel data as below - Originally I wanted to create a variable that is the sum of PRICE - but with a separate TOTAL for each different group of DATE within the same CODE and num_id.
which I was able to create with Nick Cox's code:
I had then created a variable that identifies the groups of dates within a CODE and assigned a specific number (group_id).
How can I get a mean/median for PRICE of a specific CODE using group_id as the denominator/group?
I have tried:
but this just gives the overall mean for a given CODE
And also tried:
but this just lists individual means for each unique group_id, I want an over all mean of PRICE for a given CODE for using each associated group_id (i.e. with group_id as the denominator).
If I were to tabulate CODE and the number of unique group_ids:
and I want the mean PRICE associated to given CODE with respect to the group_id (n)
Sample dataex with created variables total and group_id:
I have panel data as below - Originally I wanted to create a variable that is the sum of PRICE - but with a separate TOTAL for each different group of DATE within the same CODE and num_id.
which I was able to create with Nick Cox's code:
Code:
bysort DATE CODE num_id: egen total = total(PRICE)
Code:
egen group_id = group(DATE CODE num_id)
I have tried:
Code:
bysort group_id: egen mean_group=mean(PRICE)
And also tried:
Code:
univar PRICE if CODE==194, by(group_id)
If I were to tabulate CODE and the number of unique group_ids:
CODE | CODE (n) | group_id (n) | group_id mean PRICE |
475 | 30 | 15 | ? |
476 | 40 | 25 | ? |
Sample dataex with created variables total and group_id:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float num_id int(CODE DATE) double PRICE float(total group_id) 97 475 20473 1248 58131.02 631 97 475 20473 1441 58131.02 631 97 475 20473 2275 58131.02 631 97 475 20473 1361 58131.02 631 97 475 20473 1932 58131.02 631 97 475 20473 3058 58131.02 631 97 475 20473 15324 58131.02 631 97 475 20473 15131 58131.02 631 97 475 20473 1411 58131.02 631 97 475 20473 912.02 58131.02 631 97 475 20473 10 58131.02 631 97 475 20473 13 58131.02 631 97 475 20473 1373 58131.02 631 97 475 20473 1631 58131.02 631 97 475 20473 741 58131.02 631 97 475 20473 3819 58131.02 631 97 475 20473 4177 58131.02 631 97 475 20473 2274 58131.02 631 97 863 20485 805 31089 1062 97 863 20485 910 31089 1062 97 863 20485 10216 31089 1062 97 863 20485 3408 31089 1062 97 863 20485 1631 31089 1062 97 863 20485 304 31089 1062 97 863 20485 10071 31089 1062 97 863 20485 16 31089 1062 97 863 20485 1404 31089 1062 97 863 20485 2324 31089 1062 95 193 20570 1843 131266.5 3880 95 193 20570 1669 131266.5 3880 95 193 20570 648 131266.5 3880 95 193 20570 3126 131266.5 3880 95 193 20570 1550 131266.5 3880 95 193 20570 1373 131266.5 3880 95 193 20570 6496 131266.5 3880 95 193 20570 455 131266.5 3880 95 193 20570 597 131266.5 3880 95 193 20570 871 131266.5 3880 95 193 20570 258 131266.5 3880 95 193 20570 13231 131266.5 3880 95 193 20570 1631 131266.5 3880 95 193 20570 1884 131266.5 3880 95 193 20570 435 131266.5 3880 95 193 20570 14386 131266.5 3880 95 193 20570 4174 131266.5 3880 95 193 20570 2554 131266.5 3880 95 193 20570 6014 131266.5 3880 95 193 20570 4675 131266.5 3880 95 193 20570 6132 131266.5 3880 95 193 20570 568.5 131266.5 3880 95 193 20570 1763 131266.5 3880 95 193 20570 6134 131266.5 3880 95 193 20570 16630 131266.5 3880 95 193 20570 840 131266.5 3880 95 193 20570 5243 131266.5 3880 95 193 20570 4689 131266.5 3880 95 193 20570 21397 131266.5 3880 95 193 20632 18547.35 145158.81 5837 95 193 20632 1032.2 145158.81 5837 95 193 20632 8992.12 145158.81 5837 95 193 20632 452.24 145158.81 5837 95 193 20632 5674.88 145158.81 5837 95 193 20632 1189 145158.81 5837 95 193 20632 43607.46 145158.81 5837 95 193 20632 100.54 145158.81 5837 95 193 20632 2426.04 145158.81 5837 95 193 20632 1627.19 145158.81 5837 95 193 20632 4355.79 145158.81 5837 95 193 20632 45322.45 145158.81 5837 95 193 20632 242.74 145158.81 5837 95 193 20632 4435.02 145158.81 5837 95 193 20632 2130.08 145158.81 5837 95 193 20632 5023.71 145158.81 5837 96 470 20710 772 104797.9 8305 96 470 20710 155 104797.9 8305 96 470 20710 2004 104797.9 8305 96 470 20710 2041 104797.9 8305 96 470 20710 34746 104797.9 8305 96 470 20710 7072 104797.9 8305 96 470 20710 843 104797.9 8305 96 470 20710 13 104797.9 8305 96 470 20710 5800 104797.9 8305 96 470 20710 5996 104797.9 8305 96 470 20710 2212 104797.9 8305 96 470 20710 999 104797.9 8305 96 470 20710 382 104797.9 8305 96 470 20710 570 104797.9 8305 96 470 20710 660 104797.9 8305 96 470 20710 15273 104797.9 8305 96 470 20710 1143.88 104797.9 8305 96 470 20710 3222 104797.9 8305 96 470 20710 1548 104797.9 8305 96 470 20710 2742.02 104797.9 8305 96 470 20710 6622 104797.9 8305 96 470 20710 1865 104797.9 8305 96 470 20710 4952 104797.9 8305 96 470 20710 3165 104797.9 8305 end format %tdnn/dd/CCYY DATE
Comment