Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Creating a new numerical variable without mathematical operations


From   "liu nizi" <liunizibnu@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Creating a new numerical variable without mathematical operations
Date   Sun, 22 Oct 2006 07:19:26 +0800

Firstly,you can translate these two variables into string variables by command tostring.
Secondly, you combine these two string variable just by gen newcity=province_str+city_str
Thirdly, translate newcity into numrical variable by command destring
It does work,you can try it



From: "Ramani Gunatilaka" <ramani.gunatilaka@gmail.com>
Reply-To: statalist@hsphsun2.harvard.edu
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Creating a new numerical variable without mathematical
operations
Date: Sat, 21 Oct 2006 15:34:22 +0100

Hi Fredrick and Jeph,
Thanks for your suggestions. My problem is that the city variable does
not always have four digits. Sometimes it is two, at other times, it
is three.
Thanks anyway.
Best,
Ramani

On 21/10/06, Frederick J. Boehmke <boehmke@umich.edu> wrote:

If I understand the range of the two variables properly, perhaps:

gen newcity = 10000*province + city

will work?

On Sat, 21 Oct 2006, Ramani Gunatilaka wrote:

> Date: Sat, 21 Oct 2006 14:47:09 +0100
> From: Ramani Gunatilaka <ramani.gunatilaka@gmail.com>
> Reply-To: statalist@hsphsun2.harvard.edu
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Creating a new numerical variable without mathematical operations
>
> Dear all,
> I have two numerical variables, province and city: province has two
> digits, city has at least 4.
> eg. province= 11, city= 6227
> I want to create a new numerical variable called 'newcity' which will
> combine province and city like this:
> 116227
> This is because I have to combine this data set with another, and the
> unique identifying variable in the second data set has been
> constructed in this way.
> Can someone please tell me what command I may use?
> Thanks so much,
> Ramani
> *

>



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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