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

RE:st: basic commands question

From   "Jun Xu" <>
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

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


Hope this helps.

Jun Xu
Dept of Sociology
Indiana University

Getting married? Find tips, tools and the latest trends at MSN Life Events.

* For searches and help try:

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