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

Re: st: Some kind of count or tabulation

From   "b. water" <>
Subject   Re: st: Some kind of count or tabulation
Date   Fri, 06 Jan 2006 14:59:17 +0000

thank you svend, your egen suggestion worked. in fact earlier on, at the stage of inputting the data, i have indeed used many -replace var if- in a do-file to replace blanks with a period before running my small do-file to count but i appreciate your -foreach- help suggestion.


ps: i would not have thought what i wanted would be an egen function. instinctively i thought it would be either some kind of count or tabulation.

From: "Svend Juul" <SJ@SOCI.AU.DK>
To: <>
Subject: Re: st: Some kind of count or tabulation
Date: Fri, 6 Jan 2006 14:12:07 +0100

B. Water:

I understand that your var1-varn are string variables. For strings, the
missing value typically is a blank, not a period, so I would first:

   foreach V of varlist var1-varn {
     replace `V'="" if `V'=="."

If you feel unsecure about the above construct, you might instead give
as many replace commands as you have variables:
   replace var1="" if var1=="."

Now you can use egen's robs() function with the strok option:
   egen nonmiss = robs(var1-varn) , strok

In Stata 9 the robs() function got the more telling name rownonmiss().

Now, the variable -nonmiss- tells the number of nonmissing (i.e.
non-blank) values for each observation. Wasn't that what you were
looking for?

Hope this helps


Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796

*   For searches and help try:
Is your PC infected? Get a FREE online computer virus scan from McAfeeŽ Security.

* For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index