Dear Statalist,
I am a long time reader and I would like to thank all of you for your support and for helping the community!
I could solve many problems just from reading the archives and the FAQ.
But this time, I can not find help in the archives and FAQ and I do not know how to proceed.
Question:
I have a dataset where every observation is a list of strings. This list has a variable length (some observations have 2 strings, some have 10).
Here is a simple example with three observations. The variable names are v1, v2, v3, v4.
1: "A", "B", na, na
2: "B", na,na, na
3: "C, "D", "A", "B"
I would like to convert this dataset into a different format. The variable names should be "A", "B", "C", and "D" (or whatever other strings occur in the data). Each observation should then be a set of indicator variables (0,1), indicating whether "A", or "B", or "C" or "D" occurs or not.
The example dataset would look like this:
Variable names are "A","B","C","D" (in this order)
1: 1, 1, 0, 0
2: 0, 1, 0, 0
3: 1, 1, 1, 1
I already checked tabulate and encode, but both seem not to work for my case.
Thank you very much.
Kind regards
Joern
I am a long time reader and I would like to thank all of you for your support and for helping the community!
I could solve many problems just from reading the archives and the FAQ.
But this time, I can not find help in the archives and FAQ and I do not know how to proceed.
Question:
I have a dataset where every observation is a list of strings. This list has a variable length (some observations have 2 strings, some have 10).
Here is a simple example with three observations. The variable names are v1, v2, v3, v4.
1: "A", "B", na, na
2: "B", na,na, na
3: "C, "D", "A", "B"
I would like to convert this dataset into a different format. The variable names should be "A", "B", "C", and "D" (or whatever other strings occur in the data). Each observation should then be a set of indicator variables (0,1), indicating whether "A", or "B", or "C" or "D" occurs or not.
The example dataset would look like this:
Variable names are "A","B","C","D" (in this order)
1: 1, 1, 0, 0
2: 0, 1, 0, 0
3: 1, 1, 1, 1
I already checked tabulate and encode, but both seem not to work for my case.
Thank you very much.
Kind regards
Joern
Comment