Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: string variable question


From   Eric Booth <ebooth@ppri.tamu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: string variable question
Date   Mon, 29 Mar 2010 09:04:45 -0500

>

I'm still not sure what your data look like, but I think you are just asking how to create a row id (e.g. gen idvar = [_n] ), 
so for the earlier example:

*****
clear
inp A1 A2
1 2
2 3
3 4
5 6
end

g brand = string(A1) + "-" + string(A2)   // <--**use Martin's solution to avoid destringing later for -mds-
g brand_id = _n

**if you've got multiple rows of the same brand, 
***you can create the brand_id with something like:
*egen brand_id = group(brand)

order brand*


**mds works with the string or numeric brand id**
mds A1 A2, id(brand_id) std dim(1) addc noplot
mds A1 A2, id(brand) std dim(1) addc noplot
******


~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754



On Mar 29, 2010, at 8:49 AM, Data Analytics Corp. wrote:

> Hi,
> 
> Thanks, but this is not quite there.  A1 and A2 are numeric variables while brand just identifies the rows.  A1 and A2 actually come from an MDS.
> 
> Thanks,
> 
> Walt
> 
> 
> Eric Booth wrote:
>> 
>> Use -tostring- to combine the numeric vars, ex:
>> 
>> *****
>> clear
>> inp A1 A2
>> 1 2
>> 2 3
>> 3 4
>> 5 6
>> end
>> 
>> tostring A1 A2, replace
>> gen brand = A1 + A2
>> *****
>> 
>> ~ Eric
>> __
>> Eric A. Booth
>> Public Policy Research Institute
>> Texas A&M University
>> ebooth@ppri.tamu.edu
>> Office: +979.845.6754
>> 
>> 
>> 
>> On Mar 29, 2010, at 8:32 AM, Data Analytics Corp. wrote:
>> 
>>  
>>> Hi,
>>> 
>>> I have two numeric variables in a Stata dataset: A1 and A2.  Each has 26 elements.  I want to create a third variable, brand, as part of a do program that has 26 brand names.  I tried
>>> 
>>> gen str brand = "A" "B" and so on to "Z"
>>> 
>>> but that didn't work.  How can I create a brand variable?
>>> 
>>> Thanks,
>>> 
>>> Walt
>>> 
>>> 
>>> 
>>> -- 
>>> ________________________
>>> 
>>> Walter R. Paczkowski, Ph.D.
>>> Data Analytics Corp.
>>> 44 Hamilton Lane
>>> Plainsboro, NJ 08536
>>> ________________________
>>> (V) 609-936-8999
>>> (F) 609-936-3733
>>> walt@dataanalyticscorp.com
>>> www.dataanalyticscorp.com
>>> 
>>> *
>>> *   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/
>> 
>>  
> 
> 
> -- 
> ________________________
> 
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> walt@dataanalyticscorp.com
> www.dataanalyticscorp.com
> 
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index