Statalist


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

st: AW: dropping digits from variables in Stata 10


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: dropping digits from variables in Stata 10
Date   Mon, 23 Feb 2009 12:16:42 +0100

<> 



*************
clear*
input zip
0043232
9832423
0065434
1232009
end
gen str7 newzip = string(zip,"%07.0f")
gen newzip2=substr(newzip,1,3)
l
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Ekaterina
Hertog
Gesendet: Montag, 23. Februar 2009 12:03
An: [email protected]
Betreff: st: dropping digits from variables in Stata 10

Dear All,
I am rather new to Stata so I apologize in advance if these are rather 
silly questions, but I googled around extensively and searched Stata 
help and cannot find an adequate solution.
1) I have got a variable consisting of 7 digit zipcodes. I want to 
create a second variable which will only  consist of the first 3 digits 
of each zip-code and I cannot find a way to do it.
2) Some of the zipcodes start with 00, e.g 0037845 and Stata drops the 
front 00 turning such zipcodes into 5-digit numbers (e.g. 37845). I need 
to make Stata understand that these 00 are meaningful and return them 
back into the zipcodes and I cannot find how to do this. They were 
present in my original csv file, but when I converted it into a Stata 
file using Stattransfer they were gone.
I will be most grateful for any help or advice,
Sincerely yours,
Ekaterina

-- 
Ekaterina Hertog (née Korobtseva)
Career Development Fellow
Department of Sociology and Nissan Institute of Japanese Studies
University of Oxford

27 Winchester Road
Oxford
OX2 6NA
United Kingdom


*
*   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