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
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> [email protected]
> Sent: 20 May 2004 18:16
> To: [email protected]
> 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/