Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE:st: basic commands question


From   "Jun Xu" <mystata@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   RE:st: basic commands question
Date   Wed, 05 May 2004 14:21:01 -0500

Haven't tried why egen with by not working. There are various ways to approach this. And one of them that does not use egen and by is as follows (you can use Scott Long's _pecats to get locals: var1lbl and var2lbl :

suppose there are 10 years and 20 countries


preserve
set obs 200 // if obs <200
local var1lbl "all the vavalues of country"
local var2lbl "all the values of year"

local i = 1
foreach var1val in `var1lbl' {
foreach var2val in `var2lbl' {
replace country = `var1val' if _n =`i'
replace year = `var2val' if _n=`i'
count var3
replace cntvar3 = r(N)
}
}

keep if _n<=200
keep country year cntvar3
save whereever

restore


Hope this helps.

Jun Xu
Dept of Sociology
Indiana University

_________________________________________________________________
Getting married? Find tips, tools and the latest trends at MSN Life Events. http://lifeevents.msn.com/category.aspx?cid=married

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index