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: Generating a variable by assigning value form another variable


From   Indu Khurana <indu.statauser@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Generating a variable by assigning value form another variable
Date   Tue, 12 Jul 2011 00:52:18 -0400

Dear Statalisters,

Subject: Generating a variable by assigning value form another variable

I have a panel data of 5000 firms. Each firm can have multiple owners,
but in the first stage I identified the main owner using the  first
year data and kept it same for all 6 years.
This was done through a -reshape- command. ( In the data, if main
owner==1 means that the first person was the main owner.)

Now I have something like:
firm_id  main owner   age    gender    hours_1
1               1              30       M            20
2               2              20        F            30
3               1              30        F            35
4               1              40        M            20
5               1
Basically this is the subset from year1 of the whole data.

Now I want hours_worked each year to change because it is a  time
variant variable.

When I merge this data with the rest of the data it looks like:
firm_id main_owner age gendr hours_1 hours_01_2 hours_02_2
hours_03_2.. hours_10_2..hours_10_6
1               1              30       M            20
2               2              20        F            30
3               1              30        F            35
4               1              40        M            20
5               1

hours _01_2 means: hours worked by owner 1 in the second year.
(hours_owner number* _ year)
hours_02_2 means: hours worked by owner 2 in the second year.

there are 1 to 10 owners and it goes over for 6 years.

Now i generated 5 more variables hours_2 (for second year), hours_3,
....... hours_6

I want hours_2 to take the value from the columns:  hours_01_2
hours_02_2 hours_03_2  ......... hours_10_2.

If main owner identified in stage 1 is 1 then variable hours_2 should
take the value from hours_01_2 and if
If main owner identified in stage 1 is 2 then variable hours_2 should
take the value from hours_02_2 .....and so on..

I did:
gen hours_2=.
gen hours_3 =.
......

local xx "01 02 03 04 05 06 07 08 09 10"

for each x of local xx {
 replace hours_2 =  hours_`x' if main_owner = " `x'"
}


But this does not work.

Please guide.

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