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" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 
*
*   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