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]

st: re: string to numeric format


From   Christopher Baum <[email protected]>
To   [email protected]
Subject   st: re: string to numeric format
Date   Mon, 8 Mar 2010 14:15:48 -0500

<>
Calchas said



I have a data set of test results of many candidates in item level as follo=
ws:

Candidate1  item1a  3
Candidate1  item1b  1
Candidate1  item2a  0
Candidate1  item2b  3
.
.
.
Candidate1  item6b  2
Candidate2  item1a  1

Candidate2  item1b  2

Candidate2  item2a  3

Candidate2  item2b  2

.

.

.

Candidate2  item6b  3
Candidate3  item1a  4
...

I need to rearrange the data set into one candidate per row with their resu=
lts:

                   1a    1b    2a    2b    . . . . .     6
Candidate1    3      1      0      3                  3
Candidate2    1      2      3      2                  4
Candidate3    4 .... etc

How could I do that in the Stata data editor?=20

Also how could I change a column of numeric data to string data again? You =
1st message wasn't clear. Many thanks.



a) You can't do that in the Data Editor. What you need is -reshape-:

clear
input str10 cand str9 item resp
Candidate1  item1a  3
Candidate1  item1b  1
Candidate1  item2a  0
Candidate1  item2b  3
Candidate1  item6b  2
Candidate2  item1a  1
Candidate2  item1b  2
Candidate2  item2a  3
Candidate2  item2b  2
end
encode cand,gen(icand)
drop cand 
reshape wide resp, i(icand) j(item) string



b) There are several ways to do that (as described in IMEUS below). See the -tostring- and -decode- commands. 




Kit Baum   |   Boston College Economics and DIW Berlin   |   http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming   |   http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata   |   http://www.stata-press.com/books/imeus.html


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