Thank you so much!
Irina
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of n j cox
Sent: Wednesday, December 07, 2005 11:20 AM
To: [email protected]
Subject: st: RE: RE: referencing a specific cell
Stata's issue is with
replace pn_ocg[1] =
and what comes before or after is irrelevant.
What you want to do here is illegal. Subscripts
like [1] are not allowed on the LHS of a -generate-
command, as is tacit in the syntax diagram.
The ayntax may seem natural, but it is illegal
nevertheless.
But Stata is nevertheless trying to make sense of
what you wrote. It knows that square brackets [ ]
can signal weights, yet it also knows
that weights are not allowed in -generate-.
At that point it gives up and throws your ball back
at you with a shrug of puzzlement.
The principle to follow is that under the aegis of
-by:- the built-in _n is interpreted within groups
defined by the -by:-. Thus
bysort newt : replace frog = toad[4] if _n == 3
copies toad[4] to frog[3] within the groups of newt.
>>> Paley, Irina
Thank you so much, Kit and Nick! I really appreciate it, your
suggestions works.
Why can stata do: bysort hhid: replace pn_ocg= pn_pcg[2] if pn_ocg== .
but not: bysort hhid: replace pn_ocg[1] = pn_pcg[2] if pn_ocg== .
In the latter case it says weights are not allowed
What is it about saying replace pn_ocg[1] vs. replace pn_ocg that makes
the difference?
In general, if I want to move, within household id,
1 and 10 from second row 2nd and 3rd cell to first row 4th and 5th cell,
what do I do?
+------------------------------------------+
| hhid pn_pcg relpcg pn_ocg relocg |
|------------------------------------------|
1. | 1220 2 20 . . |
2. | 1220 1 10 . . |
+------------------------------------------+
Thanks so much!
Irina
-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Cox
Sent: Wednesday, December 07, 2005 7:25 AM
To: [email protected]
Subject: st: RE: referencing a specific cell
Kit's solution looks incomplete to me.
I guess that "second" cannot be special
unless observations are ordered within
-id- in some important way, say by time.
Thus observations must be kept in the
same relative order within -id-, which is
not guaranteed by Kit's code. One way to
do it is
sort household_id, stable
by household_id: replace wage2 = wage1[2] if wage2 == .
If there were say a time variable -time-, then
bysort household_id (time) : replace wage2 = wage1[2] if wage2 == .
Nick
[email protected]
Kit Baum
> Irina asks
>
> Suppose my data has 2 observations per household and is organized as:
>
> household_id wage of person1 wage of person2
> 1 3 .
> 1 5 .
>
>
> 2 6 .
>
> 2 7 .
>
> I would like Stata to, whenever the wage of person 2 is missing, to
> substitute into it the SECOND observation of the wage of person 1
> within that household. So I would want the data to look like:
>
> household id wage of person1 wage of person2
> 1 3 5
> 1 5 5
>
> 2 6 7
> 2 7 7
>
>
> bysort household_id: replace wage2 = wage1[2] if wage2 == .
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
--------------------------------------------------------------------------------
Next Article (by Date): Re: st: Re: how to deal with variables...(Yes it
is attrition) "Nirina M."
Previous Article (by Date): st: extended generalized Gamma distribution
"Sascha O. Becker"
Articles sorted by: [Date] [Author] [Subject]
--------------------------------------------------------------------------------
Go to Harvard School of Public Health LWGate Home Page.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/