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

st: RE: collapse in forv....


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: collapse in forv....
Date   Thu, 23 Jan 2003 09:23:01 -0000

Rajiv Mallick
> 
> I need help with running the following code.  I want column 
> totals, and a 
> simple collapse command would do the job.  But I have to 
> take column totals 
> of 1000 variables, and a huge collapse commands freezes the 
> computer.  I am 
> trying the following code.  I already have a file named 
> e:\data\pricelog.dta, and the program should be able to 
> append the existing 
> file.  But it does not.  It stops with first collapse run.  
> Do appreciate 
> your looking into it.
> 
> code
> --------
> #delimit;
> clear ;
> use "D:\Stata\auto.dta", clear;
> rename price price1;
> rename mpg price2  ;
> rename headroom price3;
> save "e:\data\auto.dta", replace;
> 
> forv i=1/3 {           ;
>   rename price`i' pa;
>   collapse (sum) pa;
>   append using "e:\data\pricelog.dta", nolabel;
>   clear;
>   use "e:\visa_clm\data\auto.dta", clear;
>             }               ;
> 
> use "e:\data\pricelog.dta", clear;
> summ;
> ----
> end of code
> 
> 
> 
> ------
> huge collapse command!!!!!
> ------
> collapse (sum)
> 
> price1	price2	price3	price4	price5	price6	
> price7	price8	price9	price10	price11	price12	
> price13	price14	price15	price16	price17	price18	
> price19	price20	price21	price22	price23	price24	
> price25	price26	price27	price28	price29	price30	
> price31	price32	price33	price34	price35	price36	
> price37	price38	price39	price40	price41	price42	
> price43	price44	price45	price46	price47	price48	
> price49	price50
> price51	price52	price53	price54	price55	price56	
> price57	price58	price59	price60	price61	price62	
> price63	price64	price65	price66	price67	price68	
> price69	price70	price71	price72	price73	price74	
> price75	price76	price77	price78	price79	price80	
> price81	price82	price83	price84	price85	price86	
> price87	price88	price89	price90	price91	price92	
> price93	price94	price95	price96	price97	price98	
> price99	price100
> 

In general, it helps to know where Stata stops 
and what error message you get. 

I haven't tried to debug this, but another way to 
tackle it is something like 

file open MYOUT using total.out, write 

foreach v of var price1-price100 { 
	su `v', meanonly 
	file write MYOUT (r(sum)) _n 
}

file close MYOUT 

type total.out

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