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

Re: st: Re: Basic Commands


From   Nick Winter <[email protected]>
To   [email protected]
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:


preserve
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

restore
--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601
*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index