Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Extracting numbers from code |
Date | Tue, 13 Nov 2012 20:55:05 +0000 |
The -strofreal()- function is using the default numeric format, which here mangles the result. Try something like forv j = 2/11 { g byte dummy`j' = (strpos(strofreal(foo, "%23.0f"), "`j'") > 0) } Nick On Tue, Nov 13, 2012 at 7:47 PM, sanja_lutzeyer@ncsu.edu <slutzey@ncsu.edu> wrote: > Hi Daniel. > > Thank you again for the code. That really helps a lot! > What I have found today, is an error that I am not sure why it occurs > or how to solve it. > While the first part of the code: > > g byte dummy1 = (substr(strofreal(a5_bc), 1, 1) == "1") & /// > (cond((strlen(strofreal(a5_bc)) < 5), > cond(!(inlist(substr(strofreal(a5_bc), 2, 1)), "0", "1"), 1, 0), 1)) > > works very well, > the second part is causing some problems > > forv j = 2/11 { > g byte dummy`j' = (strpos(strofreal(a5_bc), "`j'") > 0) > } > > The dummies are all correctly created, until the variable a5_bc has > more than 8 numbers. For example: > 12347911 is classified under dummies 1,2,3 and 7, but not under > dummies 4, 9 and 11, as it should. > 1234568910 is the longest entry I have and that also is not classified > correctly. > Is there possibly a restriction to the length of the variable? > > Kind regards > Sanja > * > * 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/