Hi all,
My aim is to make variable id to be unique and I think reshape is the command instead of collapse.
When I was tried with reshape from long to wide, error appear in output:
Some error are:
code : reshape wide hi06 hi07, i(id) j(hi01) string
output: r(109); variable hi01 is numeric
I did convert data hi01 to string
command: tostring hi01, replace
hi01 was byte now str1
and did command : . reshape wide hi06 hi07, i(id) j(hi01) string
output :
(note: j = 1 3 8)
values of variable hi01 not unique within id
Your data are currently long. You are performing a reshape wide. You
specified i(id) and j(hi01). There are observations within i(id) with the
same value of j(hi01). In the long data, variables i() and j() together
must uniquely identify the observations.
long wide
+---------------+ +------------------+
| i j a b | | i a1 a2 b1 b2 |
|---------------| <--- reshape ---> |------------------|
| 1 1 1 2 | | 1 1 3 2 4 |
| 1 2 3 4 | | 2 5 7 6 8 |
| 2 1 5 6 | +------------------+
| 2 2 7 8 |
+---------------+
Type reshape error for a list of the problem variables.
r(9);
I also did several combination to reshape, including dropping some variables that not really urgent for my analysis (especially drop variable with missing value), therefore the variables left are: id, hi01, hi06, but result almost the same either. Probably I do not really understand the reshape structure.
Thanks in advance.
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str1(hi01 hitype) byte(hi02 hi06 hi07 hi08x) str9 id
"3" "." . 3 . . "001220001"
"3" "." . 3 . . "001220002"
"3" "." . 3 . . "001220003"
"3" "." . 3 . . "001220004"
"3" "." . 3 . . "001220005"
"3" "." . 3 . . "001220011"
"3" "." . 3 . . "001250001"
"3" "." . 3 . . "001250002"
"3" "." . 3 . . "001250003"
"3" "." . 3 . . "001290001"
"3" "." . 3 . . "001290002"
"3" "." . 3 . . "001290003"
"3" "." . 3 . . "002010001"
"3" "." . 3 . . "002010002"
"3" "." . 3 . . "002010003"
"3" "." . 3 . . "002010004"
"3" "." . 3 . . "002020003"
"3" "." . 3 . . "002020007"
"3" "." . 3 . . "002030001"
"3" "." . 3 . . "002030002"
"3" "." . 3 . . "002040001"
"3" "." . 3 . . "002040002"
"3" "." . 3 . . "002090001"
"3" "." . 3 . . "002090002"
"1" "A" 3 3 . . "002090003"
"1" "D" 3 3 . . "002090003"
"1" "C" 3 3 . . "002090003"
"1" "B" 1 3 . . "002090003"
"1" "V" 3 3 . . "002090003"
"1" "C" 3 3 . . "002090006"
"1" "D" 3 3 . . "002090006"
"1" "A" 3 3 . . "002090006"
"1" "B" 1 3 . . "002090006"
"1" "V" 3 3 . . "002090006"
"3" "." . 3 . . "002090007"
"1" "D" 3 3 . . "002093102"
"1" "V" 3 3 . . "002093102"
"1" "A" 3 3 . . "002093102"
"1" "C" 3 3 . . "002093102"
"1" "B" 1 3 . . "002093102"
"3" "." . 3 . . "002093202"
"1" "D" 3 3 . . "002093301"
"1" "V" 3 3 . . "002093301"
"1" "A" 3 3 . . "002093301"
"1" "C" 3 3 . . "002093301"
"1" "B" 1 3 . . "002093301"
"3" "." . 3 . . "002100001"
"3" "." . 3 . . "002100002"
"3" "." . 3 . . "002110001"
"3" "." . 3 . . "002110002"
"3" "." . 3 . . "002120001"
"3" "." . 3 . . "002140001"
"3" "." . 3 . . "002140002"
"3" "." . 3 . . "002160001"
"3" "." . 3 . . "002180003"
"3" "." . 3 . . "002180004"
"3" "." . 3 . . "002180005"
"3" "." . 3 . . "002183101"
"3" "." . 3 . . "002190001"
"1" "B" 3 3 . . "002200001"
"1" "A" 1 3 . . "002200001"
"1" "V" 3 3 . . "002200001"
"1" "C" 3 3 . . "002200001"
"1" "D" 3 3 . . "002200001"
"3" "." . 3 . . "002210001"
"3" "." . 3 . . "002250001"
"3" "." . 3 . . "002250002"
"3" "." . 3 . . "002250007"
"3" "." . 3 . . "002260001"
"3" "." . 3 . . "002260002"
"3" "." . 3 . . "002260005"
"3" "." . 3 . . "002260006"
"3" "." . 3 . . "002270001"
"3" "." . 3 . . "002270002"
"3" "." . 3 . . "002270003"
"3" "." . 3 . . "002270004"
"3" "." . 3 . . "002270006"
"3" "." . 3 . . "002290001"
"3" "." . 3 . . "002290002"
"3" "." . 3 . . "002290006"
"3" "." . 3 . . "002300001"
"3" "." . 3 . . "002300006"
"3" "." . 3 . . "002300011"
"3" "." . 3 . . "003010001"
"3" "." . 3 . . "003010002"
"3" "." . 3 . . "003010005"
"3" "." . 3 . . "003020002"
"3" "." . 3 . . "003020003"
"3" "." . 3 . . "003030001"
"3" "." . 3 . . "003030004"
"3" "." . 3 . . "003030005"
"3" "." . 3 . . "003031201"
"3" "." . 3 . . "003040002"
"3" "." . 3 . . "003050001"
"3" "." . 3 . . "003050002"
"3" "." . 3 . . "003050004"
"3" "." . 3 . . "003050006"
"3" "." . 3 . . "003070002"
"3" "." . 3 . . "003070005"
"3" "." . 3 . . "003080001"
Related Posts with Problem with Reshape on Panel Data
replacing values of a newly generated variable by the values of previous variables using "foreach var of varlist"Hi everyone, Using the below codes, I am trying to generate a new variable (long_X6 to long_X13) and…
Remove time in datetime variableI have a variable in an imported dataset from Excel in this type and format: type: double format: %t…
Has anyone tried 'malmq2' to run a Malmquist DEA?I am a new STATA user and tried to run the captioned but return with an error msg. malmq2 is a recen…
Reshaping data from Time series form to a PanelHi, I have the following numbers (I have data on 150 such countries). I want to convert this data i…
Indicator variables with an IV (2sls) regressionHello, I am working on a project right now where I have delta_u as the dependent variable (it is the…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with Reshape on Panel Data
Post a Comment