Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: identification of particular string formats


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: identification of particular string formats
Date   Thu, 5 May 2011 18:18:54 +0100

Note for U.S. and some other readers: the reference is to British postcodes.

I'd class this problem as one of counting _distinct_ values --
although many people would say _unique_ values. There is a review at

SJ-8-4  dm0042  . . . . . . . . . . . .  Speaking Stata: Distinct observations
        (help distinct if installed)  . . . . . .  N. J. Cox and G. M. Longton
        Q4/08   SJ 8(4):557--568
        shows how to answer questions about distinct observations
        from first principles; provides a convenience command

Using the command in question

. distinct postcode if length(postcode) == 3

. distinct postcode if !strpos(postcode, " ")

are solutions. In fact -tab postcode- with the -if- conditions will
count too, although the count is returned silently in r(r).

Nick

On Thu, May 5, 2011 at 6:07 PM, Jamie Fagg <j.fagg@ich.ucl.ac.uk> wrote:

> Specification: Stata version 11.1, Windows XP
>
> I have a list of postcodes. I'd like to be able to count ones which have a
> certain format. For example, from the following list, I'd like to know that
> there are 2 postcodes with only 3 characters,
> and 2 which have no central blank. A search of the archives hasn't helped,
> mainly because I feel I'm not searching correctly.
>
> My question is therefore, for this specific example, how would I count and
> list the postcodes in question.
>
> B30
> B31
> B30 1AH
> B30 1NH
> B30 1XB
> B303RB
> B312QH
> B31 2QH
> B31 5AX
> B32 1NL
> B32 1PL
>
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index