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: Right to Left Column Cascade or Adjustment

From   David Torres <>
Subject   Re: st: Right to Left Column Cascade or Adjustment
Date   Tue, 24 May 2011 14:14:07 -0400

Thank you.
David Diego Torres, MA(Sociology)
PhD Candidate in Sociology

2044 Population Studies Center
University of Michigan Institute for Social Research
Ann Arbor MI  48106-1248
Tel 734.763.4098
Fax 734.763.1428
torresd at umich dot edu

Quoting Eric Booth <>:

On May 24, 2011, at 10:08 AM, David Torres wrote:
There's probably a proper name for the process I'd like to carry out.
Say I have five columns of information with staggard cell inputs. How do I go about moving all the information in a subsequent column back through to the first column for which no information is missing on the row?

I'm not sure what the proper name for this process is, nor could I find any existing program that would do it. The only name I could think of for this was -shiftleft- (based on option to shift cells left in MS Excel because this is the first thing I thought of when I read David's question). So, my previous example could be turned into the program below. I'll add a couple of more options and error checking into the code and submit it to Kit for after he returns to Boston.

******!draft program -shiftleft-
*! Eric A. Booth <>
*! May 2011
cap program drop shiftleft
program def shiftleft
syntax varlist
qui {
tempvar i N
g `i' = _n
reshape long Col, i(`i') j(`N')
drop `N'
drop if mi(Col)
bys `i': g `N' = _n
reshape wide Col, i(`i') j(`N')

inp Col1   Col2     Col3    Col4    Col5

101     101 . . .
.       111 . .      333
. . . .         935
. . .     023      016
405 . . .             295 .
g x = runiform()*10
g x2 = "abc"
shiftleft Col1-Col5
- Eric
Eric A. Booth
Public Policy Research Institute
Texas A&M University
Office: +979.845.6754

*   For searches and help try:

*   For searches and help try:

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