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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: How to combine variables in network data - can I loop over stubs?


From   Brandon Olszewski <olszewski.brandon@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: How to combine variables in network data - can I loop over stubs?
Date   Wed, 20 Apr 2011 16:23:17 -0700

I have a -wide- social network data set that needs some cleaning. It
contains about 40 different projects, here named AAA, BBB, CCC, etc.
Each project is connected to every other project at some level, 0 =
“no familiarity”, 1 = “familiar”, and 2 = “works with a lot”. Rows
represent projects, and columns represent the level of familiarity a
project has with others. Here is what the data look like, then:

project	AAA_0	AAA_1	AAA_2	BBB_0	BBB_1	BBB_2
AAA											1
BBB			0
Etc.

In the above example, project AAA knows B at a level 1 (familiar), and
project BBB reports not knowing project AAA (at a level 0).

I want to create variables (total_AAA, total_BBB, etc.) that combine
columns with the same stub (“AAA”, “BBB”, etc.) so that one new column
represents the three old columns. The new column would contain a value
(0, 1, or 2) that was previously represented in wide format across
three columns. Searching the statalist, the following post is the
closest I found:
http://www.stata.com/statalist/archive/2007-03/msg00234.html.

I’m thinking of using a -foreach- command to do it, but I think I
would need to loop the command over a stub, rather than a varname. I
also know how to use -renpfix- to change stub names. In my ideal
world, a solution would look like:
>>>
foreach stub of stubname AAA BBB{
	gen total`stub’=0
	replace total`stub’=2 if `stub’_1==1
	replace total`stub’=3 if `stub’_2==2
	}
keep project total*
>>>

I've racked my brain with -reshape- and some other commands I know,
but the logic eludes me and I am still unsuccessful. Can anyone help
me?

Thanks,
Brandon Olszewski
Research Associate
International Society for Technology in Education

*
*   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