Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Christopher Baum <kit.baum@bc.edu> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

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/

- Prev by Date:
**Re: st: How does Stata calculate percentiles?** - Next by Date:
**Re: st: Clustering by school year** - Previous by thread:
**st: How to expand the data using set-variables** - Next by thread:
**st: Clustering by school year** - Index(es):