[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AW: st: AW: problem with the generate command
From
Steven Samuels <[email protected]>
To
[email protected]
Subject
Re: AW: st: AW: problem with the generate command
Date
Tue, 3 Mar 2009 11:35:29 -0500
--
Eva is right. There's no need for -regexr-. With gremlins zapped,
the following works for me.
replace healthinit="" if healthinit==".."
destring healthinit, gen(h)
-Steve
On Mar 3, 2009, at 10:23 AM, Eva Poen wrote:
Isabelle,
Martin and Steven already gave you hints on how to proceed from here.
Just a few comments: Your
replace healthinit="" if "healthinit"==..
is incorrect syntax. The double quotes should be around the .. and not
around healthinit. Next you tried
replace healthinit="" if healthinit==".."
which is correct syntax. You said "it does not work". Please be more
specific. Does Stata give an error message (which is unlikely)? Or
does it say "(0 real changes made)" which means that the string ".."
cannot be found in your variable. In this case I suspect there are
either leading and/or trailing spaces around .., or some other weird
characters that came about by copy and paste. One thing you could try
is
replace healthinit="" if strpos(healthinit,"..")>0
Martin's advice to use -tab- and -tab, nolabel- after -encode- was
just meant to show you what -encode- actually does. These commands
would not change your data, therefore no change of behaviour was
expected.
If you get nowhere with string functions and/or regular expressions,
try and explore other routes to get your data into Stata, e.g.
StatTransfer, where you can declare a variable to be numeric from the
outset.
Eva
2009/3/3 <[email protected]>:
Dear all,
Thank you very much for this helpful advice.
Stata refuses to replace .. by a blank. I type:
*******
replace healthinit="" if "healthinit"==..
******
I have:"nothing found where name expected".
If I try:*replace healthinit="" if healthinit==".."*, it does not
work
better. Is there a problem with my command?
Then when I write:
**
encode healthinit, gen(H)
ta H
ta H, nolabel
generate health=1.06*H
**
I have the same resultas for health
<>
After your -encode- command, type
*************
ta H
ta H, nolabel
*************
and note the difference. -destring- is your command of choice,
and pay
attention to Eva`s remark for the missings.
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Dienstag, 3. März 2009 12:29
An: [email protected]
Betreff: Re: st: AW: problem with the generate command
Dear Martin,
Thank you very much for all your help since the beginning I use
Stata.
Here are my data (just the beginning!):
country healthinit H health
Afghanistan 13.00 13.00 23.32
Albania 116.00 116.00 16.96
Algeria 76.00 76.00 169.6
American Samoa .. .. 1.06
Andorra 1922.17 1922.17 54.06
Angola 24.00 24.00 72.08
Antigua and Barbuda 492.00 492.00 138.86
Argentina 283.00 283.00 89.04
Armenia 53.00 53.00 145.22
Aruba .. .. 1.06
Healthinit is the health expenditure per capita in current
dollars. It is
a string variable. It comes from the wdi database. As I want them in
euros, and that the exchange rate is 1.06 (year is 2003), I wrote to
stata:
encode healthinit, gen(H)
generate health=1.06*H
H is a long variable.
Danke schön für die Helfe!
Isabelle
*
* 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/
© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |