Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: generating new observations


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: generating new observations
Date   Wed, 29 Mar 2006 21:11:56 +0100

That's one interpretation of what is wanted here. 

Another is that this question is asking for ad hoc surgery to fix 
a specific problem, the fact that for trade purposes
Belgium and Luxembourg are a unit. 

We also have, on this evidence, a consistency problem, 
as "Luxemburg" and "Luxembourg" are two and the same
thing. (We professional geographers are well up on such 
details.) 

I'd do ad hoc surgery this way:  

gen byte tojoin = inlist(importer, "Belgium", "Luxembourg", "Luxemburg") 

After this, these countries code as 1 and everything else as 0. 
If you also have "Belgie", "Belgique" or any other variations, add
them to the parenthesised list. 

Now we want to add up commensurables: 

bysort tojoin commoditycode : replace tradevalue = sum(tradevalue) if tojoin 

and possibly to clean up: 

by tojoin commoditycode : keep if _n == _N  & tojoin 

But -save- the dataset first, as this may not be what you want. 

Also, isn't there a parallel issue with exporters? 

Nick 
[email protected] 

David Kantor
 
> At 12:45 PM 3/29/2006, Kremena wrote:
> >Hi,
> >
> >I have a data set with the following variables:
> >
> >importer     exporter     commoditycode   tradevalue
> >
> >Belgium      Argentina    1               123
> >Belgium      Argentina    2               456
> >Luxemburg    Argentina    1               789
> >Luxembourg   Argentina    3               147
> >
> >I want to generate new observations such that importer is 
> Belgium-Luxembourg
> >and tradevalue is the combined trade value for the two 
> countries for the
> >respective commodity.
> >
> >Can someone tell me how I can do that?
> >[...]
> 
> You can do...
> 
> collapse (sum) tradevalue , by(commoditycode)
> 
> This will sum to the level of commoditycode, regardless of importer 
> or exporter (and it won't create a combined importer identifier).  If 
> you want specific groups of importers or importer/exporter 
> combinations, you will need to do that in advance, creating another 
> variable, and then put that variable into the by() option.

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index