Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: generating number list depending on another variable
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: generating number list depending on another variable
Date
Wed, 19 Mar 2014 15:20:58 +0000
The solution (whether converting to 1-100 or 2345-2434) should be quite simple, but you need to tell us what you have done so far. For example, what did the variable look like when it was a string? What did you do to convert it to numeric? What does it look like now?
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Patricia Biedermann
Sent: Wednesday, March 19, 2014 11:17 AM
To: [email protected]
Subject: Re: st: generating number list depending on another variable
It was a string and is now numeric (I also needed it numeric for other
analysis).
Anyway, I will see if I find a solution. I just need to create a new
variable with new ID numbers, not necessarily from 1-100, but e.g.
2345-2434;
Variable1 Variable2
AL 2345
AL 2345
BS 2355
BS 2355
BS 2355
SF 2356
etc.
Sorry for my blurry communication.
On Wed, Mar 19, 2014 at 4:03 PM, Richard Goldstein
<[email protected]> wrote:
> you should not be using -egen- at all as far as I can see
>
> you have now contradicted yourself (is variable 1 numeric or string?) so
> maybe someone else can help you
>
> Rich
>
> On 3/19/14, 10:58 AM, Patricia Biedermann wrote:
>> Hello,
>> -decode seems not to work with string variables. So I used encode.
>> - When I generate variable2 with egen variable2=fill(1(1)100) I get
>> this result:
>>
>> Variable 1 Variable 2
>> AL 1
>> AL 2
>> AL 3
>> BS 4
>> BS 5
>> BS 6
>> BS 7
>> BS 8
>> SF 9
>> SF 10
>> ZG 11
>> etc etc.
>>
>> On Wed, Mar 19, 2014 at 3:52 PM, Richard Goldstein
>> <[email protected]> wrote:
>>> then -decode- it is one option
>>>
>>> however, if it is already numeric doesn't it already meet what you want?
>>> if not, what is wrong with it?
>>>
>>> Rich
>>>
>>> On 3/19/14, 10:49 AM, Patricia Biedermann wrote:
>>>> Hi Richard,
>>>> Thanks for your reply. Variable 1 is already encoded....it's a long
>>>> variable now.
>>>> Pati
>>>>
>>>>
>>>> On Wed, Mar 19, 2014 at 3:43 PM, Richard Goldstein
>>>> <[email protected]> wrote:
>>>>> it looks like variable 1 is a string variable so you want the -encode-
>>>>> command; when you read the help file, pay attention to the "label" option
>>>>>
>>>>> Rich
>>>>>
>>>>> On 3/19/14, 10:34 AM, Patricia Biedermann wrote:
>>>>>> Dear all,
>>>>>>
>>>>>> Following problem:
>>>>>> I have variable1 with different values (AL, BS, SF, ZK...etc.) and
>>>>>> want to create another variable with a list of numbers reaching from
>>>>>> e.g. 1-100;
>>>>>> For each value in variable1 there should be the same number in
>>>>>> variable2; it should look like that in the end:
>>>>>>
>>>>>> Variable 1 Variable 2
>>>>>> AL 1
>>>>>> AL 1
>>>>>> AL 1
>>>>>> BS 2
>>>>>> BS 2
>>>>>> BS 2
>>>>>> BS 2
>>>>>> BS 2
>>>>>> SF 3
>>>>>> SF 3
>>>>>> ZG 4
>>>>>> etc etc.
>>>>>>
>>>>>> I tried to use egen variable2=fill(1(1)100) also in combination with
>>>>>> foreach; somehow generates values from 1-100 independently from
>>>>>> Variable 1
>>>>>>
>>>>>> Thank you!
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/