Here is one way:
tempfile foo
clear
input str14 country code year seiz
"Britain" 200 1980 100
"Britain" 200 1981 150
"US" 2 1980 200
"US" 2 1981 250
"Brit Virg Isl." . 1980 50
"Brit Virg Isl." . 1981 75
"Cayman Isl." . 1980 50
"Cayman Isl." . 1981 75
"US Virg Isl." . 1980 50
"US Virg Isl." . 1981 75
end
gen id = 1 if country == "Britain" | country == "Brit Virg Isl." ///
| country == "Cayman Isl."
replace id = 2 if country == "US" | country == "US Virg Isl."
sort code year
save `foo'
collapse (sum) seizplus = seiz (mean) code, by(id year)
sort code year
merge code year using `foo'
sort country code year
move seizp seiz
drop _m
l
Scott
On Feb 8, 2008 5:38 PM, Lektzian, David <[email protected]> wrote:
> Dear Statlist:
>
> I'm stuck and was hoping somebody could help. I have data on country,
> country code (ccode), year (1980-2007), and drug seizures.
>
> I want to make a new variable drug seizure plus that adds seizures from
> overseas territories to a country's total. For example, I have:
>
> Country code year seiz seizplus
> Britain 200 1980 100 200
> Britain 200 1981 150 300
> .
> .
> .
> US 2 1980 200 250
> US 2 1981 250 325
> .
> .
> .
> Brit Virg Isl. . 1980 50
> Brit Virg Isl. . 1981 75
> .
> .
> .
> Cayman Isl. . 1980 50
> Cayman Isl. . 1981 75
> .
> .
> .
> US Virg Isl. . 1980 50
> US Virg Isl. . 1981 75
>
> The country codes are missing for those "countries" that are not really
> countries. What I want to do is to identify which territories belong to
> which countries and then write a line of code that adds seiz for Britain
> in 1980 to seizures for Brit Virg Isl + Cayman Isl. +....etc for all
> their territories. Then I would repeat for the US, France, Netherlands,
> etc. I'm guessing there is an easy way to do this, but I don't know how
> to add two values in the same variable at different years, matching them
> based on a string name and then putting the sum in an additional
> variable. I have to do this for 8 different types of drug seizures so I
> didn't want to just do it by hand. After I capture this additional
> seizure data, I will then drop the territories from the analysis as they
> do not match with other variables in the analysis I need to do.
>
> Any help would be greatly appreciated.
>
> Thanks,
> Dave
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/