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]

From |
Daniel Marcelino <[email protected]> |

To |
[email protected] |

Subject |
Re: st: identifying how many digits string var has |

Date |
Sun, 3 Apr 2011 14:55:56 -0300 |

Yeah, thinking better the problem, my test is ilogical. Thanks Daniel On Sun, Apr 3, 2011 at 4:28 AM, Nick Cox <[email protected]> wrote: > Joerg Luedicke gave you a solution with -length()-. > > -strlen()- and -length()- are just different names for the same function. > > What you did wrong was that > > ... if strlen(`x') > > is to be thought of as a contraction for > > ... if strlen(`x') > 0 > > which is true for all your tests. So, the last test you made > overwrites the others. > > As Joerg said, just using -length()- or -strlen()- to count the > characters is what you want. > > Nick > > On Sun, Apr 3, 2011 at 1:38 AM, Daniel Marcelino <[email protected]> wrote: > >> Is there a way to identify how many digits a string var have? In the >> following example I have 18 , 14, and "missing" digits (counting "/". >> "-" and "."). So, I want to identify in var2 how many digits per line >> var1 has. >> >> gen str20 var1 = "" >> input >> "12.205.291/0001-33" >> "12.176.958/0001-17" >> "589.275.222-49" >> "409.011.140-49" >> "12.147.825/0001-12" >> "010.433.392-80" >> "07.752.894/0001-15" >> "." >> end >> >> >> I tried this loop, but it just returned me value "3" for all obs. What is wrong? >> >> foreach x of varlist var1 { >> generate byte var2 = 1 if strlen(`x') >> replace var2 = 2 if strlen(`x') >> replace var2 = 3 if strlen(`x') >> } > * > * 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: identifying how many digits string var has***From:*Daniel Marcelino <[email protected]>

**Re: st: identifying how many digits string var has***From:*Nick Cox <[email protected]>

- Prev by Date:
**st: How to test the statistical significance of difference between parameters obtained from xtprobit model in two sub-sample** - Next by Date:
**st: pseudo R-squared** - Previous by thread:
**Re: st: identifying how many digits string var has** - Next by thread:
**st: ivprobit what do "s21 s31 s32, etc" mean?** - Index(es):