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

Re: st: Re: Basic Commands

From   Nick Winter <>
Subject   Re: st: Re: Basic Commands
Date   Wed, 05 May 2004 15:55:00 -0400

This syntax provides an excellent example of the fact that there are many ways to skin most cats in Stata. Note, though, that as Nick Cox pointed out, the -contract- command in fact does exactly this.

Another option is:

. collapse (count) var3 , by(var1 var2)

--Nick Winter

At 02:29 PM 5/5/2004 -0500, you wrote:

Just to corrent my awkward syntax here:

set obs 200 // if obs <200
local var1lbl "all the vavalues of country"
local var2lbl "all the values of year"
gen country=.
gen year=.
gen cntvar3=.

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) if _n=`i'
  local ++i

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

Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government e
308 White Hall w
Cornell University
Ithaca, NY 14853-4601
* For searches and help try:

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