Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[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?
clear
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
list
Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/