Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to expand the data using set-variables

From   Christopher Baum <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: How to expand the data using set-variables
Date   Sun, 24 Oct 2010 08:45:30 -0400

On Oct 24, 2010, at 2:33 AM, Badri wrote:

> I have a global tariff data that contains observations corresponding
> to sectors (defined by variable sec), exporters (defined by variable
> exp) and importers (defined by variable imp). Both exp and imp are
> sets, but defined in numbers.
> While there is data for all observations corresponding to exp and imp
> elements that are not identical ( exp!=imp), there are no observations
> where exp==imp. Now I want to expand the data by a number of
> observations that have exp==imp. I know the number of observations
> required to do this. Is there any way I can do this in stata? Mata
> programming or other simpler ways?

set obs 100
g expno = ceil(_n/10) 
g impno = mod(_n,10)+1
g fakeflow = runiform()*100
drop if expno == impno
sort expno impno
// data now contain exp-imp pairs lacking those with exp==imp
expand 2, gen(newobs)
egen tt = tag(expno) if newobs
drop if newobs & !tt
replace fakeflow = . if newobs
replace impno = expno if tt
sort expno impno
// data should now contain records for exp==imp with missing values for fakeflow

Kit Baum   |   Boston College Economics & DIW Berlin   |
                              An Introduction to Stata Programming  |
   An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index