Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Arranging variables across rows


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Arranging variables across rows
Date   Wed, 27 Jun 2012 18:49:46 +0100

Yes; you are missing sth here, apart from a tacit Statalist convention
that we are not texting each other.

I am not looping across observations, but suffixes of variable names.
Besides, references to variables A and B would fail as ambiguous given
Samuel's explanation that he has variables A1...A19 and B1...B8. Also,
loops 1...19 or 1...8 would fail to do anything to most of Samuel's
12,000 or so observations.

Further, when you say

the macros are declared to substitute "_n" (obs no)

that is not necessarily true. (Where did you read this?)  In Stata
programming practice it is only occasionally true. Macros can stand in
for anything you want that is text.

Nick

On Wed, Jun 27, 2012 at 6:38 PM, tashi lama <ltashi32@hotmail.com> wrote:
> I am just curious.....the macros are declared to substitute "_n"(obs no). I would assume that we write replace D[`i'], A[`j'] and B[`k'] instead of D`i', A`j' etc. Am I missing sth here?
>
>
>
> Thanx
>
> ----------------------------------------
>> Date: Wed, 27 Jun 2012 18:26:18 +0100
>> Subject: Re: st: Arranging variables across rows
>> From: njcoxstata@gmail.com
>> To: statalist@hsphsun2.harvard.edu
>>
>> Given your determination to keep your present data structure, I can
>> also suggest a clumsy way to do it. The precise code is untested.
>>
>> forval i = 1/19 {
>> gen D`i' = 0
>> forval j = 1/19 {
>> forval k = 1/8 {
>> replace D`i' = 1 if A`j' == B`k' & B`k' < .
>> }
>> }
>> }
>>
>> Nick
>>
>> On Wed, Jun 27, 2012 at 5:10 PM, samuel gyetvay <sam.gyetvay@gmail.com> wrote:
>> > Thank you for all your help, I feel I am already making some progress.
>> >
>> > I realize, however, that I was not perfectly clear or explicit about
>> > the form or structure of my data. Your responses so far are still very
>> > useful and appropriate.
>> >
>> > A1, ... A19, B1, ... B8 are names of (column) variables, each of which
>> > contain ~12,000 entries. There exists a variable that identifies
>> > families, call it fam, although it does not always identify family
>> > uniquely. There does exist a variable that identifies family
>> > respondent, however, call it famr. fam and famr are also column
>> > variables, each of which contain ~12,000 entries.
>> >
>> > For the moment, my analysis is quite simple; it only requires some row
>> > and column summation, and the current form of the data is quite nice
>> > for what I have to do (for the most part). Nearly all of the variables
>> > that I need to use are just like A1, ... A19. For example, a set of
>> > variables that identify "sex of child," call them C1, ... C19 overlap
>> > perfectly with A1, ..., A19, and you can easily control for sex of
>> > child when doing row and column summation, because their positions
>> > coincide. For example, the third value of C13 will identify the sex of
>> > the same child as the third value of A13.
>> >
>> > B1, ... B8 is the only problematic variable, because it does not
>> > overlap: it merely indicates which child identification number
>> > received treatment. So you cannot use a simple command such as
>> >
>> > . count if A`j' == B`j'
>> >
>> > Which I can do for other variables. What I would like to do is to
>> > create dummy variables D1, ..., D19 equal to 1 when the child has
>> > received treatment, and 0 otherwise. That way I can use it just like I
>> > used C1, ..., C19.
>> >
>> > I apologize for not being more clear from the start, and appreciate
>> > everything you have suggested thus far.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index