I googled and tried many command from yesterday and until now it's still unsuccessful. Could you please expert help me on this? Thank you very much in advance.
My data is like this --->
6 types
2 years : 18-19, 19-20
many districts
type | year | district | budget | Q1 | Q2 | Q3 |
DS | 18-19 | Love | 10 | 8 | 1 | 1 |
DS | 19-20 | Love | 6 | 2 | 2 | 4 |
EDU | 18-19 | Chiniot | 5 | 1 | 1 | 1 |
EDU | 19-20 | Chiniot | 4 | 3 | 3 | 3 |
HLT | 18-19 | Chiniot | 10 | 2 | 2 | 2 |
HLT | 19-20 | Chiniot | 8 | 1 | 1 | 1 |
EDU | 18-19 | Jhang | 4 | 4 | 4 | 4 |
EDU | 19-20 | Jhang | 2 | 2 | 2 | 2 |
HLT | 18-19 | Jhang | 3 | 3 | 3 | 3 |
HLT | 19-20 | Jhang | 1 | 1 | 1 | 1 |
DS | 19-19 | Cute | 10 | 3 | 3 | 3 |
DS | 19-20 | Cute | 2 | 1 | 1 | 1 |
HLT | 18-19 | Harnai | 20 | 10 | 10 | 10 |
DS | 18-19 | Harnai | 4 | 4 | 4 | 4 |
HLT | 19-20 | Sibi | 2 | 2 | 2 | 2 |
DS | 18-19 | Sibi | 5 | 2 | 2 | 3 |
1) I want to clone everything if var district aren't these name
"Chiniot", "Jhang", "Harnai","Sibi", "Lakki" "Bannu" "Nushki" "Chagai"
2) But if the districts name above: I want to collapse (sum) by each type (DS sum with DS) and each year (18-19 with 19-20) with condition below
sum of "Chiniot", "Jhang", ------> and using district name "Chiniot"
sum of "Harnai","Sibi", ------> and using district name "Harnai"
sum of "Lakki" "Bannu" ------> and using district name "Lakki"
sum of "Nushki" "Chagai" ------> and using district name "Nushki"
The result that I expect would be
ype | year | district | budget | Q1 | Q2 | Q3 |
DS | 18-19 | Love | 10 | 8 | 1 | 1 |
DS | 19-20 | Love | 6 | 2 | 2 | 4 |
EDU | 18-19 | Chiniot | 9 | 5 | 5 | 5 |
EDU | 19-20 | Chiniot | 6 | 5 | 5 | 5 |
HLT | 18-19 | Chiniot | 13 | 5 | 5 | 5 |
HLT | 19-20 | Chiniot | 9 | 2 | 2 | 2 |
DS | 19-19 | Cute | 10 | 3 | 3 | 3 |
DS | 19-20 | Cute | 2 | 1 | 1 | 1 |
HLT | 18-19 | Harnai | 20 | 10 | 10 | 10 |
DS | 18-19 | Harnai | 4 | 4 | 4 | 4 |
HLT | 19-20 | Sibi | 9 | 6 | 6 | 7 |
All experts in STATA: Could you please help me with this?
I tried foreach, collapse, egen, gen, clonevar, but it didn't work.
Thank you very much.
0 Response to Panel - Loop collapse or egen with condition
Post a Comment