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: st: Arranging variables across rows
From
tashi lama <[email protected]>
To
<[email protected]>
Subject
RE: st: Arranging variables across rows
Date
Wed, 27 Jun 2012 15:10:50 +0000
COuld you do sth like this...
if you have a saved file containing B1, B2....B8 and you open a file containing A1, A2...A19. Note the latter file is your master file.
var1 id |
|------------|
1. | A1 101 |
2. | A2 102 |
3. | A3 103 |
4. | A4 104 |
5. | A5 105 |
|------------|
6. | A6 106 |
7. | A7 107 |
8. | A8 108 |
9. | A9 109 |
10. | A10 110 |
|------------|
11. | A11 111 |
12. | A12 112 |
13. | A13 113 |
14. | A14 114 |
15. | A15 115 |
|------------|
16. | A16 116 |
17. | A17 117 |
18. | A18 118 |
19. | A19 119 |
var1 id |
|------------|
1. | B1 103 |
2. | B2 101 |
3. | B3 102 |
4. | B4 105 |
5. | B5 110 |
|------------|
6. | B6 104 |
7. | B7 113 |
8. | B8 115 |
+------------+
merge 1:1 id using t1.dta, keep(match master)
gen check1=string(_merge)=="3" will give you
var1 id _merge check1 |
|---------------------------------------|
1. | A1 101 matched (3) 1 |
2. | A2 102 matched (3) 1 |
3. | A3 103 matched (3) 1 |
4. | A4 104 matched (3) 1 |
5. | A5 105 matched (3) 1 |
|---------------------------------------|
6. | A6 106 master only (1) 0 |
7. | A7 107 master only (1) 0 |
8. | A8 108 master only (1) 0 |
9. | A9 109 master only (1) 0 |
10. | A10 110 matched (3) 1 |
|---------------------------------------|
11. | A11 111 master only (1) 0 |
12. | A12 112 master only (1) 0 |
13. | A13 113 matched (3) 1 |
14. | A14 114 master only (1) 0 |
15. | A15 115 matched (3) 1 |
|---------------------------------------|
16. | A16 116 master only (1) 0 |
17. | A17 117 master only (1) 0 |
18. | A18 118 master only (1) 0 |
19. | A19 119 master only (1) 0 |
+---------------------------------------+
Tashi..
subinstr("`doc_type'"," ","",1)subinstr("`doc_type'"," ","",1)> Date: Tue, 26 Jun 2012 17:37:23 -0400
> Subject: st: Arranging variables across rows
> From: [email protected]
> To: [email protected]
>
> I have two sets of variables, let's call them A1, A2, ... A19 and B1,
> B2, ... B8.
>
> A1, A2, ... A19 give identification numbers for up to 19 individuals
> per family. Each family occupies a row in the data set.
>
> B1, B2, ... B8 list identification numbers of up to 8 individuals who
> have received treatment.
>
> I need to preserve the order and placement of variables in A1, ... A19
> and would like to create a dummy variable equal to 1 whenever an
> individual has received treatment. Basically, I need to go from
> something that like this:
>
> A1 A2 A3 ... A19
> 101 102 103 ... 19
>
> B1 B2 B3 ... B8
> 103 . . ... .
>
> To something like this
>
> A1 A2 A3 ... A19
> 101 102 103 ... 119
>
> D1 D2 D3 ... D19
> 0 0 1 ... 0
>
> I am aware of the command rowsort, but it does not solve this
> particular problem. rowsort would turn
>
> B1 B2 B3 ... B8
> . . 102 ... .
>
> into
>
> B1 B2 B3 ... B8
> 102 . . ... .
>
> when what I need is
>
> B1 B2 B3 ... B8
> . 102 . ... .
>
> I could create a dummy variable equal to 1 when A is equal to B
>
>
> Hopefully this question is clearly phrased, and there exists a simple
> solution. Please let me know if you have any suggestions or if
> anything is unclear.
>
> Thank you,
>
> -S
>
> *
> * 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/