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


From   "Vassilopoulos Achilleas" <[email protected]>
To   <[email protected]>
Subject   st: RE: Generating a variable by assigning value form another variable
Date   Tue, 12 Jul 2011 08:42:49 +0300

The problem is within the loop; your notation is a bit sloppy there. This
should work:

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

foreach x of local xx {
 replace hours_2 =  hours_`x'_2 if main_owner == `x'
}
 
Hope this helps, 
_____________ - _______________

Achilleas Vassilopoulos

Agricultural University of Athens,
Dept. of Agricultural Economics and Rural Development,
Lab. of Political Economy and European Integration.
Iera Odos 75, 11855, Athens, Greece

Tel: (+30) 210-5294726
Fax: (+30) 2105294786
e-mail : [email protected] 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Indu Khurana
Sent: Tuesday, July 12, 2011 7:52 AM
To: [email protected]
Subject: st: Generating a variable by assigning value form another variable

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/

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