Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: RE: AW: summarize variables without collapsing


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: RE: AW: summarize variables without collapsing
Date   Mon, 13 Apr 2009 22:01:29 +0200

<> 

This is how you could "make the return list permanent" with -postfile-.
Substitute a permanent instead of a -tempfile- if desired.

*************
  *Example, postfile as temp
        
        use  http://www.stata-press.com/data/r10/nlswork.dta, clear
        
        * make sure nothing left over
        cap postutil clear
        di in red _rc
        
        *get temps
        tempname hdle
        tempfile info
        postfile `hdle' occ min max mean using `info'
        
		*cycle through the levels of occ, in your case "state"
        levels occ_co, local(myloc)
        qui foreach lev of local myloc{
        	*substitute "income" for "hours"
        	su hours if occ_co==`lev', meanonly
        	post `hdle' (`lev') (r(min)) (r(max)) (r(mean))
         }
        
        postclose `hdle'
        
        preserve
       	 use `info', clear
       	 list, noo sep(0)
        restore
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Brent Fulton
Gesendet: Montag, 13. April 2009 21:44
An: [email protected]
Betreff: st: RE: AW: summarize variables without collapsing 

Thank you, Martin. The issue is that -return list- only gives the last
state.

In the interim I figured out an alternative.

bysort state: gen stateobs=_n

su income if stateobs==1

-Brent


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Monday, April 13, 2009 12:32 PM
To: [email protected]
Subject: st: AW: summarize variables without collapsing 


<> 

Easy answer:

*************
by state, sort : summarize income, detail
*************

Does that do what you want? If not, why not?


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Brent Fulton
Gesendet: Montag, 13. April 2009 21:26
An: [email protected]
Betreff: st: summarize variables without collapsing 

Dear Statalist,

I am using Stata 9.2 and have a dataset with 10,000 individuals who each
reside in one of 50 states. I have individual-level (e.g., race) and
state-level variables (e.g., a state's average income).

Is there a way to summarize the average income (calculate mean, min, max,
sd, etc.) for the 50 states without collapsing the data by state?

Thanks,
Brent Fulton
UC Berkeley

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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