Bookmark and Share

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


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

st: RE: Creating a new variable via another variable name based on a condition


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Creating a new variable via another variable name based on a condition
Date   Thu, 8 Jul 2010 20:46:13 +0100

(You should -update- to 8.2. It's free.) 

You should -reshape- your data to -long-. Then no loops are required. 

You don't give variable names. I will assume 

Firm identifier: id 
Hours worked by owners 1, 2, etc.: hours1, etc. 
Equity owned by owners 1, 2, etc.: equity1, etc. 

The -reshape- is 

reshape long hours equity, i(id) 

Then 

rename _j owner
mvencode *, mv(0) override
bysort id (hours equity) : gen main = owner[_N]

Repeat: no loops. 

Nick 
[email protected] 

Indu Khurana

Creating a new variable via another variable name based on a condition

Using stata 8.0. I am trying to create a logical condition which would
copy the name of the variable if satisfied.

Here is what I have:

Aim is to identify the main owner. I have generated one variable Main
Owner
I assign value to this variable using maximum no. of hours worked.

I have information on
1. Total 10 owners. Sometimes there may be only 1 or 2 owners.
2. Hours - Number of hours worked per week.
3. Equity - Equity ownership by each worker.
I have data for 5 years. There are approximately 5000 firms.

There are 2 issues:
1. Lets say there are 2 owners (1 and 2) . Owner1 works for 3 hours
and Owner2 works for 2 hours, then I want the variable main owner to
take the value 1. How can I post the name of the variable and not the
value?
2. Now if the hours worked for the owners are the same I use Equity
ownership as the variable to resolve the tie. In that case owner with
maximum equity ownership becomes the main owner. How to create a loop
for this?

1st year data


Firms Hrs owner1 Hrs owner2  Hrs owner3  main owner
1             3                2               0                  1
2              2               3              6                   3
3              3               8               .                   2
4              2                .              2         tie - go to
equity
.
.
.
5000

Firms Equity ownr1  Equity ownr2  Equity owner3  main ownr
1                50                25                      25         1
2                25                50                      25         3
3                75                25                       .          2
4                80                 .                       20         1
.
.
.
5000


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index