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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

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

Subject |
st: RE: RE: St: replace in |

Date |
Fri, 24 Oct 2008 15:37:43 +0100 |

(Apologies for previous incomplete version.) To elaborate on Martin's comment: This is nothing to do with -for-. At Eric's request, I won't lecture him against using -for-. I'll just explain to everyone else that -for- is outdated, slow, and may bite you, just like a bad-tempered dog in retirement. Still, you may have good feelings for that dog, remembering happier days. Eric's problems would arise with e.g. replace lbmlifexint1993[_40] = lbmlifexint1993[_41] if lbmlifexint1993[_41] == . The underscores don't belong here. (Perhaps Eric is thinking somehow of _n.) replace lbmlifexint1993[40] = lbmlifexint1993[41] if lbmlifexint1993[41] == . Now see things from Stata's viewpoint. The syntax for -replace- is replace oldvar =exp [if] [in] setting aside an option not relevant here. So nothing can go before the = sign except the name of an existing variable. Stata gawks at Eric's syntax and its best guess from the [ ] it sees is that Eric is trying to use weights where they can't be used. Hence the error message. Stata can't read your mind, so it guesses according to syntax rules. Now Eric wants replace lbmlifexint1993 = lbmlifexint1993[41] in 40 if lbmlifexint1993[41] == . or more to the point replace lbmlifexint1993 = lbmlifexint1993[41] in 40 if lbmlifexint1993[40] == . which might as well be replace lbmlifexint1993 = lbmlifexint1993[41] in 40 if lbmlifexint1993 == . Nick n.j.cox@durham.ac.uk Martin Weiss Try this: ************ sysuse auto, clear list mpg trunk in 23/24 replace mpg=2 in 23 replace mpg=trunk in 24 list mpg trunk in 23/24 ************ Do not try this: replace mpg[23]=2 Eric Uslaner I have some historical data with different rows for countries such as the Czech Republic and the old Czechoslovakia. I'd like to replace the missing values for the Czech Republic with those for the former Czechoslovakia (yes I know that there is a Slovakia--but I'll handle that separately). The row for the Czech Republic is 40 and for Czechoslovakia is 41. So I tried to type: for var bmginiint1820-lbmlifexint1993: replace X[_40]=X[_41] if X[_41]==. (and please don't lecture me on using the "for" command). But I keep getting the error message: weights not allowed r(101); Can I do this? In the past I have just cut and pasted the data, but I have a large number of variables and this could get awkward. * * 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: St: replace in***From:*"Eric Uslaner" <euslaner@gvpt.umd.edu>

**st: RE: St: replace in***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: RE: St: replace in***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: Logistic regression** - Next by Date:
**st: RE: RE: St: replace in** - Previous by thread:
**st: RE: RE: St: replace in** - Next by thread:
**st: Problem with replace if - test condition works only for some values of test variable** - Index(es):

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