Statalist The Stata Listserver


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

st: RE: ouput tables using command 'display'


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: ouput tables using command 'display'
Date   Sun, 29 Jan 2006 23:15:45 -0000

You can nest -forval- loops. But your example
shows that you know that already, so I 
can't see what's behind this post.  

However, a larger question is why you are 
doing it this way. Your table problem
does not look very unusual. 

Nick 
n.j.cox@durham.ac.uk 

Hui Wang
 
> I am trying to do a table contenting condictional counting 
> results in each 
> cell. To output the table automatically, I want to save the 
> count result in 
> macros and then use 'display' to show them in rows and columns.
> 
> The following is the main code. Where each row is the 
> individual's current 
> age and each column is the age at marriage, so that the 
> number in row i and 
> column j represents the number of people who is i years old 
> now got married 
> when he is j years old.
> 
> ******Counting*********************************************
> forvalue i=12/51 {
>    forvalue j=11/38 {
>    count if age==`i' & marr_age==`j'
>    local t4a_`i'`j'=r(N)
>    }
> }
> 
> *****Display***********************************************
> forvalue i=12/51 {
>   display `t4a_`i'11' ","	`t4a_`i'12' ","	`t4a_`i'13' ","	
> `t4a_`i'14' 
> ","	`t4a_`i'15' ","	`t4a_`i'16' ","	`t4a_`i'17' ","	`t4a_`i'18' 
> ","	`t4a_`i'19' ","	`t4a_`i'20' ","	`t4a_`i'21' ","	`t4a_`i'22' 
> ","	`t4a_`i'23' ","	`t4a_`i'24' ","	`t4a_`i'25' ","	`t4a_`i'26' 
> ","	`t4a_`i'27' ","	`t4a_`i'28' ","	`t4a_`i'29' ","	`t4a_`i'30' 
> ","	`t4a_`i'31' ","	`t4a_`i'32' ","	`t4a_`i'33' ","	`t4a_`i'34' 
> ","	`t4a_`i'35' ","	`t4a_`i'36' ","	`t4a_`i'37' ","	`t4a_`i'38' ","
> }
> 
> The results looks likt the following:
> 
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0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0,0,0,0,0,1,4,4,6,1,6,2,0,3,0,0,0,0,1,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,1,4,7,6,8,7,1,0,0,0,1,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,3,5,9,12,9,10,7,7,2,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,2,4,6,10,2,7,14,13,7,5,1,0,0,0,1,0,0,0,0,0,0,0,
> 
> In the display part, I only use loop structure for the rows 
> but not the 
> columns, which makes the programming a bit complicated to write.
> 
> So my question is that is there any way that I can also write a loop 
> structure for the columns to get the same output results as 
> above? How to 
> use more than one loop in the display command so that the 
> program can out 
> put the table that I want?
> 

*
*   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–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index