Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: Replacing observations with values from other observations

From   Ryan Stevens <>
Subject   Re: st: Replacing observations with values from other observations
Date   Fri, 31 May 2013 16:42:10 -0400


To reference observations in Stata you use [#] after your variable, so
observation number 6 for var1 can be accessed as var1[6]. Now you have
to remember your obsID variable and the observation number according
to Stata may be different. So your code could look like:

replace var1 = var1[6] if obsID==5

This replaces the var1 with the value of var1 at Stata observation 6
if obsID==5. Now this could all be simplified if obsID matches Stata's
observation numbers. If there is a one-to-one mapping of obsID to
Stata's observation numbering you can do this as

replace var1 = var1[6] in 5

This replaces the value of observation 6 at observation 5.


On Fri, May 31, 2013 at 4:31 PM, Pounds, Moses A.
<> wrote:
> Hello everyone,
> I would like to replace specific observations with values from other observations. I can use
> replace var1 = 500 if obsID==5
> to replace the value for variable 1 in the observation with ID number 5, with the quantity 500. What I would like is code that allows me to make a reference to another observation, in place of that "500." Does anyone have a way to do this? (My option of last resort is to do this in Excel, but I would prefer to keep working in Stata.)
> Thanks in advance for any help you can give,
> Moses
> ----------------------------------------
> Moses A. Pounds
> Program Evaluator
> Baltimore City Public Schools
> Office of Achievement and Accountability
> NOTICE: The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained herein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator.
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index