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]

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: number generation |

Date |
Mon, 31 May 2010 00:00:32 +0200 |

<> " perhaps the %03s was the problem and when changed to "%03.0f" did it" See -help f_string- which talks about "numeric display format": string(n,s) Domain n: -8e+307 to 8e+307 and missing Domain s: strings containing %fmt numeric display format -tostring- is a wrapper for -string()- so the same insights apply there. HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tyler Frazier Sent: Sonntag, 30. Mai 2010 23:47 To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: number generation I am exporting to a text file, and while the zeros were appearing in the stata data editor, each time I used outsheet, the leading zeros were dropped perhaps the %03s was the problem and when changed to "%03.0f" did it ***** bysort plot: gen bldg=string(_n, "%03.0f") ***** works like a charm thanks Martin! On Sun, May 30, 2010 at 11:33 PM, Martin Weiss <martin.weiss1@gmx.de> wrote: > > <> > > Not sure what you are trying to do. If you want the counter as strings (why > would you want that?), you can just say > > *********** > bysort plot: gen bldg=string(_n) > *********** > > -string()- happily accepts -format- as well. > > > -tostring-`s -format()- option accepts _numeric_ formats, as you are moving > from numeric to string. If you want to -format- the finished results, do it > in a separate line, just as you seem to be implying. > > > HTH > Martin > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tyler Frazier > Sent: Sonntag, 30. Mai 2010 22:45 > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: RE: number generation > > I found this works, but it seems the format option should be in the > same line with -tostring- > > ****** > bysort plot: gen bldg=_n > > tostring bldg, gen(bldg1) > > format %003s bldg1 > ******* > > > On Sun, May 30, 2010 at 10:31 PM, Tyler Frazier <tyfrazier@gmail.com> wrote: >> I came up with this short code based on your recommendation -- the >> bysort works fine, but I am having problems with the format option, >> its syntax I believe. >> >> ******* >> bysort plot: gen bldg=_n >> >> tostring bldg, gen(bldg1) format(%3s) >> ******* >> >> >> On Sun, May 30, 2010 at 7:14 PM, Martin Weiss <martin.weiss1@gmx.de> > wrote: >>> >>> <> >>> >>> The solution could be as easy as >>> >>> >>> *********** >>> bysort block: gen bldg=_n >>> *********** >>> >>> See NJC`s http://www.stata-journal.com/sjpdf.html?articlenum=pr0004 >>> >>> >>> HTH >>> Martin >>> >>> >>> -----Original Message----- >>> From: owner-statalist@hsphsun2.harvard.edu >>> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tyler Frazier >>> Sent: Sonntag, 30. Mai 2010 19:02 >>> To: statalist@hsphsun2.harvard.edu >>> Subject: st: number generation >>> >>> I would like to generate a method to number buildings in sequence, but >>> restart the sequence in accordance with a group. For example I have >>> the following nomenclature >>> >>> (block) (round) (plot) (bldg) >>> 005 050 010 xxx >>> 005 050 020 xxx >>> 005 050 030 xxx >>> 005 050 040 xxx ... >>> >>> 005 050 150 xxx ... >>> >>> 005 060 010 xxx ... >>> >>> 010 010 010 xxx ... >>> >>> >>> where xxx represents a unique object identifier. I'm thinking to use >>> gen or egen with a cond() qualifier, but how to set the parameters for >>> the unique object identifier such that it returns sets of the >>> following structure >>> >>> 005 050 010 001 >>> 005 050 010 002 >>> 005 050 010 003 ... >>> >>> 005 050 010 999 >>> >>> thank you, >>> Ty >>> * >>> * 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/ > * * 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/

**References**:**st: number generation***From:*Tyler Frazier <tyfrazier@gmail.com>

**Re: st: RE: number generation***From:*Tyler Frazier <tyfrazier@gmail.com>

**Re: st: RE: number generation***From:*Tyler Frazier <tyfrazier@gmail.com>

**Re: st: RE: number generation***From:*Tyler Frazier <tyfrazier@gmail.com>

- Prev by Date:
**Re: st: RE: number generation** - Next by Date:
**st: Executing mata drop within a do file after an if condition** - Previous by thread:
**Re: st: RE: number generation** - Next by thread:
**st: new package zoib available from SSC** - Index(es):