Hello everyone. Thank you for your time to read my question. The below dataset consists of countries and industries. For industries, they are both in columns and rows. This is a sample data that I created following format of the World Input and Output Dataset (please ignore the numerical values: they are randomly assigned). To summarize, I want to add a new row that calculates sum of asian country's values so that the new observation at the last row will show the sum of asian countries's industries' values. I was thinking first to make a dummy variable indicating whether the country listed in country variable is Asian country. After that, I wanted to sum the column by industry, conditioning on country being Asian country(i.e. Japan and China in this sample). However, I was not sure how I could proceed this. Summing the row seems to be much easier which can be done by egen rowtotal if... Could someone please give me adivse to creating the new observation at the last row that calculates the conditional sum of column? Thank you in advance for your help!
Code:
clear
input industry country fish forestry manufacture etc
10 1 1294.2 112.5 324.1 1.33
20 1 83.0 3.2 32.1 323.1
30 1 19.1 333.1 5.1 1312.1
10 2 877.4 3.1 3232.1 3.2
20 2 283.1 4.1 3154.2 3.1
30 2 2999.1 2.1 13.2 1.44
10 3 115.9 31.1 0.3 333.1
20 3 1590.8 4.5 1.3 92.1
30 3 42.0 8.2 5.23 0.2
10 4 1321.3 93.1 1.23 33.2
20 4 321.0 134.2 33.2 1.2
30 4 32.4 315.1 3.1 33.2
end
label values industry vlindustry
label def vlindustry 10 "fishing" 20 "forestry" 30 "manufacture", modify
label values country vlcountry
label def vlcountry 1 "US" 2 "Japan" 3 "Canada" 4 "China", modify
0 Response to Create observations (i.e. adding a row) in the dataset
Post a Comment