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]

st: Ordering a varlist according to "parent" and "child" variables

From   A Loumiotis <>
Subject   st: Ordering a varlist according to "parent" and "child" variables
Date   Mon, 19 Dec 2011 18:15:18 +0200


I'm working with survey data where the variables are related in the
following way.  There are "parent" and "child" variables where each
"child" variable can have at most one "parent" variable.  What I would
like to do is to find a general way to reorder the initial varlist in
a way that the "child" variables follow right after the "parent"

Consider the following simplified example of a survey dataset with 11
variables var1-var11.

var1 has three "child" variables var2-var4
var3 has two "child" variables var5-var6
var5 has two "child" variables var8-var9
var7 has one "child" variable var11

What I would like to do is to find a (general) way to reorder the
initial varlist var1-var11 as follows:

var1 var2 var3 var5 var8 var9 var6 var4 var7 var11 var10

What I have done up to now is to create locals for each variable that
contains the child variables if any.  For the simplified example these
locals are defined as follows:

local childofvar1 var2 var3 var4
local childofvar2
local childofvar3 var5 var6
local childofvar4
local childofvar5 var8 var9
local childofvar6
local childofvar7 var11
local childofvar8
local childofvar9
local childofvar10
local childofvar11

I've tried to use loops to generate the ordered varlist but I'm not
successful.  Any help will be greatly appreciated!!!


*   For searches and help try:

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