Bookmark and Share

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: AW: AW: st: string variable question


From   Roger Newson <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: AW: AW: st: string variable question
Date   Mon, 29 Mar 2010 16:14:15 +0100

You could have used a value label, together with -decode-. As in:

gene int brandseq=_n
lab def brandseq 1 "Cheerios" 2 "Wheaties" 3 "Frosted"
lab val brandseq brandseq
decode brandseq, gene(brand)

Alternatively, you could have used -sdecode- (downloadable from SSC), instead of -decode-, if you didn't want to have the numeric variable -brandseq- at the end. As in:

gene int brand=_n
lab def brand 1 "Cheerios" 2 "Wheaties" 3 "Frosted"
lab val brand brand
sdecode brand, replace

I hope this helps.

Best wishes

Roger


On 29/03/2010 16:04, Data Analytics Corp. wrote:
This seems to get the job done.  Tedious, but it works.  Why can't I
just create a string vector as in R?

Martin Weiss wrote:
<>

" I should be able to do something like

             gen str brand = "Cheerios" "Wheaties" "Frosted" etc"




Only one -gen- statement is necessary/allowed for "brand", such as - gen str
brand = "Cheerios"-. Subsequently you replace via - replace brand =
"Wheaties" in 2-...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Data Analytics
Corp.
Gesendet: Montag, 29. März 2010 16:24
An: [email protected]
Betreff: Re: AW: st: string variable question

Hi,

Sorry, but I'm not making myself clear.  Let me try again.  Here's the data:

A1   A2
1.35   -2.48
1.50   0.56
0.75   -1.2
...

I want to add a third variable, brand, that has nothing to do with the
specific numbers for A1 and A2, but rather with the rows.  So, I want

             A1   A2         brand
             1.35   -2.48   Cheerios
             1.50   0.56     Wheaties
             0.75   -1.2      Frosted
             ...

A1 and A2 come from an MDS estimation by converting the e(Y) matrix to
variables.  I now need to add the brands for further processing.  It
seems I should be able to do something like

             gen str brand = "Cheerios" "Wheaties" "Frosted" etc

But it doesn't work, unless I just mistyped something.  Hope this helps
clarify what I need.  I really appreciate the help.

Thanks,

Walt


Martin Weiss wrote:

<>

Or, in one fell swoop:

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

gen brand=string(A1)+string(A2)
list
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Eric Booth
Gesendet: Montag, 29. März 2010 15:38
An: [email protected]
Betreff: Re: st: string variable question



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
[email protected]
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
[email protected]
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/


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









--
Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/

Opinions expressed are those of the author, not of the institution.

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index