Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Question regarding displaying Count, number of missing values,min, max in one table


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Question regarding displaying Count, number of missing values,min, max in one table
Date   Fri, 18 Oct 2013 00:07:01 +0100

I didn't think it would seem cryptic, but here are some comments:

sysuse auto, clear

That just feeds in some data as an example.

foreach v of var * {

You loop over all variables, numeric and string. -summarize-, to be
used shortly, won't choke on string variables. However, it could be
worthwhile filtering out the string variables using -ds- or -findname-
(SJ, SSC).

su `v', meanonly

-summarize, meanonly- gives enough information for everything you need
to be worked out. But it doesn't show anything. It just leaves stuff
in memory.

di abbrev("`v'", 24) _col(25) %8.0f _N  %8.0f _N - r(N) %8.0g r(min) ///
%8.0g r(max)

So, we need to -display- stuff.

abbrev("`v'", 24)

shows the variable name, here arbitrarily abbreviated to 24
characters. Use any variant on 24.

_col(25)

move to column 25 regardless, so output is aligned. 25 = 24+1,
clearly. If you changed 24, change this too.

%8.0f _N

display the number of observations (format guessed); if count means
the number of non-missing values, use r(N) here

%8.0f _N - r(N)

display the number of missing values (the difference between the
number of observations and the number of non-missing values)

%8.0g r(min) %8.0g r(max)

display the minimum and maximum

}

end of loop






}
Nick
[email protected]


On 17 October 2013 16:16, Michael Stewart
<[email protected]> wrote:
> Hi ,
> Thank you very much for your time and such a nice  code.It took me
> some time but i finally understood it.
> Thanks
> Anwar
>
> On Thu, Oct 17, 2013 at 8:25 AM, Nick Cox <[email protected]> wrote:
>> sysuse auto, clear
>> foreach v of var * {
>>  su `v', meanonly
>>  di abbrev("`v'", 24) _col(25) %8.0f _N  %8.0f _N - r(N) %8.0g r(min) ///
>> %8.0g r(max)
>> }
>>
>>
>> Nick
>> [email protected]
>>
>>
>> On 17 October 2013 10:45, Michael Stewart
>> <[email protected]> wrote:
>>> Hi ,
>>>
>>> This might be a simple question for some stata users ... but sorry, I
>>> am not able to get it .
>>>
>>> I am working with multiple (really huge ) datasets, each with 152
>>> variables. After  extracting data and converting to stata format using
>>> the load programs, I am checking accuracy of my conversion by
>>> comparing summary statistics of my datasets with the ones supplied by
>>> data supplier.
>>>
>>> As part of this, I am trying to get the following statistics for
>>> continuous variables   in my dataset  displayed as  one single table
>>>
>>> 1)Count
>>> 2)number of missing values
>>> 3)min
>>> 4)max
>>>
>>> I can get these values from codebook which is not in a table format.
>>>
>>> i can also get  these values using tabstat command  but cant get
>>> number of msising values as a column along with count, min, max in
>>> same table.
>>>
>>> Can any one please help if there are any user written programs or
>>> tricks with stata commands
>>>
>>> Thank you very much for your time.
>>>
>>>
>>> --
>>> Thank you ,
>>> Yours Sincerely,
>>> Mike.
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
>
> --
> Thank you ,
> Yours Sincerely,
> Mike.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index