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

From |
Michael Hanson <mshanson@mac.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: regexr and missing values |

Date |
Fri, 17 Oct 2008 20:35:46 -0400 |

Howie:

gen test = lfpatfin replace test = regexs(1)+"E" if regexm(lfpatfin,"^([A-Z]*)U$") 2) Wrap your -regexr()- command in a -cond()- statement, i.e.: gen test = cond(missing(lfpatfin), "", regexr(lfpatfin,"U$", "E"))

HTH, Mike On Oct 17, 2008, at 4:34 PM, Howard Lempel wrote:

Hello all,I'm using Stata 10 (last updated 10/10/07) and am having a bit oftrouble with the -regexr- function. I can't tell if I've stumbledon a bug or if I'm doing something wrong.I am trying to use -regexr- to transform a string variable calledlfpatfin. I'd like to take every observation where the last letterin lfpatfin is "U" and substitute an "E" for the "U". The codeappears to work except that two observations where lfpatfin wasmissing have been replaced with an "E". This appears to be similarto a problem Yun Liu had with -regexm- on July 16 in this thread:http://www.stata.com/statalist/archive/2008-07/msg00596.html, but Ican't tell if Yun's issue was ever resolved. I have been unable toreproduce the problem using the auto dataset or a dataset genericdataset I created. My code and some output follows. I did nothingto test in between generating it and the -list- command.gen test = regexr(lfpatfin,"U$", "E") list lfpatfin test in 1/1000 if lfpatfin != test +-----------------+ | lfpatfin test | |-----------------| 70. | FRU FRE | 105. | RFU RFE | 148. | U E | 161. | U E | 554. | FU FE | |-----------------| 861. | FU FE | 914. | U E | +-----------------+ list lfpatfin test if missing(lfpatfin) & !missing(test) +-----------------+ | lfpatfin test | |-----------------| 20074. | E | 24067. | E | +-----------------+ . list lfpatfin test in 16000/16200 if missing(lfpatfin) +-----------------+ | lfpatfin test | |-----------------| 16156. | | 16162. | | 16166. | | 16170. | | 16175. | | |-----------------| 16176. | | 16179. | | 16180. | | 16183. | | 16186. | | |-----------------| 16197. | | +-----------------+For what it's worth, I try to make similar changes to lfpatfin(substituting "B"s for final "D"s) later in my code and had thesame problem.I'd appreciate it a lot if anyone has any explanation. I also donot know how to see what Stata has updated since my last update,but I would be grateful if anyone knows where to go for that - I'dlike to check whether the -regex- functions have been changed.Unfortunately, I don't have the admin rights to update my versionof Stata.Thanks for your consideration. Howie Howie Lempel Research Assistant The Brookings Institution | Economic Studies 1775 Massachusetts Ave NW | Washington DC 20036 hlempel@brookings.edu | p: (202) 238-3576 * * 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/

**Follow-Ups**:**RE: st: regexr and missing values***From:*Howard Lempel <HLempel@brookings.edu>

**References**:**st: regexr and missing values***From:*Howard Lempel <HLempel@brookings.edu>

- Prev by Date:
**st: RE: Re: RE: Re: regexr and missing values** - Next by Date:
**Re: st: Re: changing format** - Previous by thread:
**st: Re: RE: Re: regexr and missing values** - Next by thread:
**RE: st: regexr and missing values** - Index(es):

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