[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
siyama@who.int |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: RE: RE: RE: RE: RE: RE: Using postfile |

Date |
Fri, 21 May 2004 09:59:34 +0200 |

Nick Cox, you are the BEST EVER!!!! Many many thanks. Amani -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 20 May 2004 20:18 To: statalist@hsphsun2.harvard.edu Subject: st: RE: RE: RE: RE: RE: Using postfile That's much clearer, thanks. For what I now think you want, the matrices are at best a means to an end and at worst a complete distraction. You can go from dataset to dataset. Here is a silly example: ----------------- u auto, clear foreach v of var turn trunk foreign { bysort rep78 `v' : gen f_`v'_ = _N separate f_`v'_, by(`v') foreach w of var `r(varlist)' { bysort rep78 (`w') : replace `w' = `w'[1] replace `w' = 0 if mi(`w') } local vars "`vars' `r(varlist)'" } keep rep78 `vars' bysort rep78: keep if _n == 1 -------------------- here is a more general script ----------------------- u <dataset>, clear foreach v of var <column variables> { bysort <rowvar> `v' : gen f_`v'_ = _N separate f_`v'_, by(`v') foreach w of var `r(varlist)' { bysort <rowvar> (`w') : replace `w' = `w'[1] replace `w' = 0 if mi(`w') } local vars "`vars' `r(varlist)'" } keep <rowvar> `vars' bysort <rowvar>: keep if _n == 1 ------------------------ There's probably a quicker way, but I hope that helps. Nick n.j.cox@durham.ac.uk > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of > siyama@who.int > Sent: 20 May 2004 18:16 > To: statalist@hsphsun2.harvard.edu > Subject: st: RE: RE: RE: RE: Using postfile > > > Hello again, > > I apologize that my query still lacks clarity. I will go back to > auto.dta, for example there are two tabulations below: > > tab rep78 for, matcell(new) > Repair | > Record | Car type > 1978 | Domestic Foreign | Total > -----------+----------------------+---------- > 1 | 2 0 | 2 > 2 | 8 0 | 8 > 3 | 27 3 | 30 > 4 | 9 9 | 18 > 5 | 2 9 | 11 > -----------+----------------------+---------- > Total | 48 21 | 69 > tab rep78 wg, matcell(newg) > Repair | > Record | wg > 1978 | 0 1 | Total > -----------+----------------------+---------- > 1 | 0 2 | 2 > 2 | 0 8 | 8 > 3 | 1 29 | 30 > 4 | 5 13 | 18 > 5 | 1 10 | 11 > -----------+----------------------+---------- > Total | 7 62 | 69 > > matrix list new > new[5,2] > c1 c2 > r1 2 0 > r2 8 0 > r3 27 3 > r4 9 9 > r5 2 9 > > matrix list newg > newg[5,2] > c3 c4 > r1 0 2 > r2 0 8 > r3 1 29 > r4 5 13 > r5 1 10 > > I wish to output the content of the matrices "new" and "newg" > to one dataset > (or *.txt) whose records will be r1-r5 and variables will be > c1 c2 c3 c4. > > I hope that is clearer and my apologies for the confusion once again. > > Best regards, > > Amani > * * 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/ * * 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/

- Prev by Date:
**st: treatment of "$" in graphics text** - Next by Date:
**st: Plotting residuals along with 95% confidence intervals** - Previous by thread:
**st: treatment of "$" in graphics text** - Next by thread:
**st: Plotting residuals along with 95% confidence intervals** - Index(es):

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