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

st: RE: RE: RE: series of value labels and collapse


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: series of value labels and collapse
Date   Tue, 8 Jul 2003 19:51:45 +0100

Adama Konseiga 

> For those 
> interested the alternative to my previous posting is:
> *=====================================
> u ctypes, clear 
> drop *_*
> egen cmiss = rmiss(c?) 
> gen cpresent = 3 - cmiss
> tab cpresent cmixtures
> drop cmixtures-cpresent 
> reshape long c, i(id plot) 
> drop if area == . 
> drop if id == . 
> drop if c == . 
> su 
> bysort id plot : gen Area = area / _N 
> tabstat Area, by(c) s(sum)
> *======================================

What's the moral here? Adama had a structure of 

* several farmers 

* each farmer can have several plots (i.e. one or more)

* each plot can have several crop types (i.e. one or more)

The interest lies in various reductions 
of the data. The most flexible structure 
is a "long long" structure, e.g. 

farmer plot crop 
id            c 
1        1    1
1        1    2 
1        2   42 
1        3   77 
2        1   11
2        1   12 
2        2   42 

etc.  

after which the key tool is -by:-. 
Looping over the possibilities with -forval- or 
-foreach- is then unnecessary and we have 
an example of "programming without programming". 

-reshape-s to "long long" are also 
discussed at 
http://www.stata.com/support/faqs/data/reshape3.html

Nick 
[email protected] 
*
*   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