*****************************************************************************************
* Stata program for the conversion of data from the India NSS57 survey
* from ASCII format to Stata format.
* This program converts data from Schedule 2.345 and adds variables and value labels.
*
* Author: Cathrine Machingauta, World Bank Data Group (Sept. 2012)
*****************************************************************************************

clear
set mem 900M
set more off

global pathin  "Q:\India\IND_2001_NSS57-SCH2.345_v01_M\Data\Original"
global pathout "Q:\India\IND_2001_NSS57-SCH2.345_v01_M\Data\Stata"
#delimit ;


***************************************************************;
* SCHEDULE 2.345 - Workfile1-Blocks 1 and 10              ;
***************************************************************;

local workfile1 R U;

foreach i in `workfile1' {;

	drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B1_v17		293
	str S2345B1_v18		294
	str S2345B10_v3	    59-61
	
using "$pathin\WHCC201`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B1_v17	"Informant code" ;
la var S2345B1_v18	"Response code" ;
la var S2345B10_v3 "Time taken to canvas";
la var weight "Weighting coefficient";

cap la def state
1	"Jammu & Kashmir"
2	"Himachal Pradesh"
3	"Punjab"
4	"Chandigarh"
5	"Uttaranchal"
6	"Haryana"
7	"Delhi"
8	"Rajasthan"
9	"Uttar Pradesh"
10	"Bihar"
11	"Sikkim"
12	"Arunachal Pradesh"
13	"Nagaland"
14	"Manipur"
15	"Mizoram"
16	"Tripura"
17	"Meghalaya"
18	"Assam"
19	"West Bengal"
20	"Jharkhand"
21	"Orissa"
22	"Chattigarh"
23	"Madhya Pradesh"
24	"Gujarat"
25	"Daman & Diu"
26	"Dadra & Nagar Haveli"
27	"Maharashtra"
28	"Andhra Pradesh"
29	"Karnataka"
30	"Goa"
31	"Lakshdweep"
32	"Kerala"
33	"Tamil Nadu"
34	"Pondicherry"
35	"A & N Islands"

cap la val state state;

cap la def sector 1 "Rural" 2 "Urban" ;
cap la val sector sector ;

cap la def enterp_type 1 "OAE" 2 "establishment";
cap la val enterp_type enterp_type;

cap la def svy_code
1 "original enterprise surveyed" 
2 "substitute surveyed" 
3 "casualty";
cap la val svy_code svy_code;

cap la def subst_rsn 
 1 "Informant busy"
 2 "Not available" 
 3 "Non-cooperative" 
 9 "Others";
cap la val subst_rsn subst_rsn;

cap la def BAG 
1 "Storage and warehousing(NIC-98code6302)"
2 "Hotel(NIC-98code551)"
3 "Post and telecommunications NIC-98code64)"
4 "Mechanized road transport(NIC-98code6021,60221,60231)"
5 "Real estate, renting and business activities(NIC-98code70,71,72,73,74)"
6 "Health and social work(NIC-98 code 85)"
7 "Restaurant(NIC-98 code 552)"
8 "Education(NIC-98 code 80)"
9 "Other community, social and personal service activities & other transport-(NIC-98code601,60222,60232,61,6301,6303,6304,6309,90,911,9191,92,93)";
cap la var BAG BAG;

cap la def S2345B1_v17 
1"owner/partner"
2"manager"
9"others";
cap la val S2345B1_v17  S2345B1_v17 ;

cap la def S2345B1_v18
1"Informant co-operative and capable"
2"Co-operative but not capable" 
3"Busy"
4"Reluctant"
9"Others";
cap label val S2345B1_v18 S2345B1_v18;

order entid state;
sort entid;		
save "$pathout\WHCC201`i'_B1_10.dta", replace;
};

use "$pathout\WHCC201R_B1_10.dta", clear;
append using "$pathout\WHCC201U_B1_10.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk1_10.dta",replace;
erase "$pathout\WHCC201R_B1_10.dta";
erase "$pathout\WHCC201U_B1_10.dta";

***************************************************************;
* SCHEDULE 2.345 - Workfile1-Block 2              ;
***************************************************************;

local workfile1 R U;

foreach i in `workfile1' {;

	drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B2_v1	    62
	str S2345B2_v3	    63
	str S2345B2_v4	    64
	str S2345B2_v5	    65
	str S2345B2_v6	    66
	str S2345B2_v7	    67
	str S2345B2_v8	    68
	str S2345B2_v9	    69
	str S2345B2_v10	    70-71
	str S2345B2_v11	    72-73
	str S2345B2_v12	    74-75
	str S2345B2_v13	    76-77
	str S2345B2_v14	    78
	str S2345B2_v15	    79
	str S2345B2_v16	    80
	str S2345B2_v17	    81-82
	str S2345B2_v18	    83
	str S2345B2_v19	    84-85
using "$pathin\WHCC201`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B2_v1  "Mixed activity code";
la var S2345B2_v3  "Nature of operation";
la var S2345B2_v4  "Type of ownership code";
la var S2345B2_v5  "Social group of owner";
la var S2345B2_v6  "Location of enterprise";
la var S2345B2_v7  "Whether pvt. Non-profit institution";
la var S2345B2_v8  "Account maintained code";
la var S2345B2_v9  "Whether registered (y/n)";
la var S2345B2_v10 "Registered act - 1";
la var S2345B2_v11 "Registered act - 2";
la var S2345B2_v12 "Nature-problem-1";
la var S2345B2_v13 "Nature-problem-2";
la var S2345B2_v14 "Work-on-contract";
la var S2345B2_v15 "Type-assistance-1";
la var S2345B2_v16 "Type-assistance-2";
la var S2345B2_v17 "No-of-other-activity";
la var S2345B2_v18 "Status-of-enterprise";
la var S2345B2_v19 "No-of-months-operated";
la var weight "Weighting coefficient" ;

la val sector sector;
la val state state;
la val svy_code svy_code;
la val enterp_type enterp_type;
la val subst_rsn subst_rsn;
la val BAG BAG;

cap la def S2345B2_v1 1 "Yes" 2 "No";
la val S2345B2_v1 S2345B2_v1;

cap la def S2345B2_v4
1 "Proprietary (Male)"
2 "Proprietary(Female)" 
3 "Partnership with members of the same household" 
4 "Partnership between members not all from the same household"
5 "Co-operative society"
6 "Limited company (outside public sector)"
9 "Others" ;
cap la val S2345B2_v4 S2345B2_v4;

cap la def S2345B2_v6
1 "Within household premises"	
2 "Outside household premises-fixed premises and permanent structure"	
3 "Outside household premises-fixed premises and temporary structure/kiosk/stall"	
4 "Outside household premises-without fixed premises(street vendors, etc.)"
5 "Mobile market"
6 "without fixed premises(street vendors, etc.)"; 
cap la val S2345B2_v6 S2345B2_v6;

foreach x in S2345B2_v10 S2345B2_v11 {;
cap la def `x'
1 "Municipal corporation, panchayat,local body"
2 "Shops and establishments act"
3 "Sales tax act"
4 "Motor vehicles act"
5 "Indian vessels act/merchant shipping act"
6 "Bar council"
7 "Chartered accountants act"
8 "Directorate of education / AICTE /NCTE"
9 "Medical practitioners act"
10"Co-operative societies act"
11"Societies act"
12"Indian charitable act"
13"Cinematograph act"
14"Factories act other than section 2m(i)or 2m(ii))"
99"Other (please specify)";
cap la val `x' `x';
};

foreach x in S2345B2_v12 S2345B2_v13 {;
cap la def `x'
1 "Non-availability of electricity connection"
2 "Power cut"
3 "Shortage of capital"
4 "Marketing of products/services"
5 "Lack of other infrastructure facilities"
6 "Local problems"
7 "Harassment"
8 "Competition from other  units" 
9 "Non-availability of labour" 
10"Labour problems" 
11"Fuel not available or available at exorbitant price" 
12"Non-recovery of service charges/fees/credit" 
13"No specific problem" 
99"Others please specify in the space provided)";
cap la val `x' `x';
};

foreach x in S2345B2_v15 S2345B2_v16 {;
cap la def `x'
1 "Financial loan"
2 "Subsidy"
3 "Machinery/equipment"
4 "Training"
5 "Marketing" 
6 "Procurement of raw material"
7 "No assistance received from any source"
9 "Others" ;
cap la val `x' `x';
};

order entid state;
sort entid;		
save "$pathout\WHCC201`i'_B2.dta", replace;
};

use "$pathout\WHCC201R_B2.dta", clear;
append using "$pathout\WHCC201U_B2.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk2.dta",replace;
erase "$pathout\WHCC201R_B2.dta";
erase "$pathout\WHCC201U_B2.dta";

***************************************************************;
* SCHEDULE 2.345 - Workfile1- Blocks 3 and 4                   ;
***************************************************************;
/*Blocks 3 and 4 totals are in block 5. No data on blocks 3 and 4.*/


***************************************************************;
* SCHEDULE 2.345 - Workfile1- Block 5                                ;
***************************************************************;
/*Note: Yearly values are obtained from the monthly values by 
multiplying 12 in case of perennial & casual enterprises and 
no. of months operated in case of seasonal enterprises.*/


local workfile1 R U;
foreach i in `workfile1' {;
drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B5_v1_501	161-172
	str S2345B5_v1_502	173-184
	str S2345B5_v1_503	185-196
	str S2345B5_v1_509	197-208
	
	using "$pathin\WHCC201`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B5_v1_501	"Yearly expenses" ;
la var S2345B5_v1_502	"Yearly-distributive-expenses" ;
la var S2345B5_v1_503	"Yearly receipt" ;
la var S2345B5_v1_509	"Yearly-gross value added-production" ;
la var weight "Weighting coefficient" ;

la val sector sector;
la val state state;
la val svy_code svy_code;
la val enterp_type enterp_type;
la val subst_rsn subst_rsn;
la val BAG BAG;

order entid state;
sort entid;		
save "$pathout\WHCC201`i'_B5.dta", replace;
};

use "$pathout\WHCC201R_B5.dta", clear;
append using "$pathout\WHCC201U_B5.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk5.dta",replace;
erase "$pathout\WHCC201R_B5.dta";
erase "$pathout\WHCC201U_B5.dta";


***************************************************************;
* SCHEDULE 2.345 - Workfile1- Block 6                                 ;
***************************************************************;
/*Note: Yearly values are obtained from the monthly values by 
multiplying 12 in case of perennial & casual enterprises and 
no. of months operated in case of seasonal enterprises.*/


local workfile1 R U;
foreach i in `workfile1' {;
drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B6_v1_3	86-88
	str S2345B6_v1_4	89-91
	str S2345B6_v1_5	92-94
	str S2345B6_v1_6	95-97
	str S2345B6_v1_7	98-100
	str S2345B6_v2_3	101-103
	str S2345B6_v2_4	104-106
	str S2345B6_v2_5	107-109
	str S2345B6_v2_6	110-112
	str S2345B6_v2_7	113-115
	str S2345B6_v3_3	116-118
	str S2345B6_v3_4	119-121
	str S2345B6_v3_5	122-124
	str S2345B6_v3_6	125-127
	str S2345B6_v3_7	128-130
	str S2345B6_v4_3	131-133
	str S2345B6_v4_4	134-136
	str S2345B6_v4_5	137-139
	str S2345B6_v4_6	140-142
	str S2345B6_v4_7	143-145
	str S2345B6_v5_3	146-148
	str S2345B6_v5_4	149-151
	str S2345B6_v5_5	152-154
	str S2345B6_v5_6	155-157
	str S2345B6_v5_7	158-160
		
using "$pathin\WHCC201`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B6_v1_3	"Own-full-female" ;
la var S2345B6_v1_4	"Own-full-male" ;
la var S2345B6_v1_5	"Own-part-female" ;
la var S2345B6_v1_6	"Own-part-male" ;
la var S2345B6_v1_7	"Own-total-worker" ;
la var S2345B6_v2_3	"Hired-sk-full-female" ;
la var S2345B6_v2_4	"Hired-sk-full-male" ;
la var S2345B6_v2_5	"Hired-sk-part-female" ;
la var S2345B6_v2_6	"Hired-sk-part-male" ;
la var S2345B6_v2_7	"Hired-sk-total-worker" ;
la var S2345B6_v3_3	"Hired-unsk-full-female" ;
la var S2345B6_v3_4	"Hired-unsk-full-male" ;
la var S2345B6_v3_5	"Hired-unsk-part-female" ;
la var S2345B6_v3_6	"Hired-unsk-part-male" ;
la var S2345B6_v3_7	"Hired-unsk-total-worker" ;
la var S2345B6_v4_3	"Other-full-female" ;
la var S2345B6_v4_4	"Other-full-male" ;
la var S2345B6_v4_5	"Other-part-female" ;
la var S2345B6_v4_6	"Other-part-male" ;
la var S2345B6_v4_7	"Other-total-worker" ;
la var S2345B6_v5_3	"Total-full-female" ;
la var S2345B6_v5_4	"Total-full-male" ;
la var S2345B6_v5_5	"Total-part-female" ;
la var S2345B6_v5_6	"Total-part-male" ;
la var S2345B6_v5_7	"Total-worker" ;
la var weight       "Weighting coefficient" ;

la val sector sector;
la val state state;
la val svy_code svy_code;
la val enterp_type enterp_type;
la val subst_rsn subst_rsn;
la val BAG BAG;

order entid state;
sort entid;		
save "$pathout\WHCC201`i'_B6.dta", replace;
};

use "$pathout\WHCC201R_B6.dta", clear;
append using "$pathout\WHCC201U_B6.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk6.dta",replace;
erase "$pathout\WHCC201R_B6.dta";
erase "$pathout\WHCC201U_B6.dta";


***************************************************************;
* SCHEDULE 2.345 - Workfile2-Block 7               ;
***************************************************************;

local workfile2 R U;

foreach i in `workfile2' {;

	drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B7_v1_1	59-70
	str S2345B7_v1_2	71-82
	str S2345B7_v1_3	83-94
	
using "$pathin\WHCC202`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B7_v1_1	"Yearly salary";
la var S2345B7_v1_2	"Yearly group benefits";
la var S2345B7_v1_3	"Yearly total salary";
la var weight       "Weighting coefficient" ;

la val sector sector;
la val state state;
la val svy_code svy_code;
la val enterp_type enterp_type;
la val subst_rsn subst_rsn;
la val BAG BAG;

order entid state;
sort entid;		
save "$pathout\WHCC202`i'_B7.dta", replace;
};

use "$pathout\WHCC202R_B7.dta", clear;
append using "$pathout\WHCC202U_B7.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk7.dta",replace;
erase "$pathout\WHCC202R_B7.dta";
erase "$pathout\WHCC202U_B7.dta";

***************************************************************;
* SCHEDULE 2.345 - Workfile2-Block 8               			   ;
***************************************************************;

local workfile2 R U;

foreach i in `workfile2' {;

	drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B8_v1_3	335-346
	str S2345B8_v1_4	347-358
	str S2345B8_v1_5	359-370
	str S2345B8_v1_6	371-382
	str S2345B8_v2_3	383-394
	str S2345B8_v2_4	395-406
	str S2345B8_v2_5	407-418
	str S2345B8_v2_6	419-430
	str S2345B8_v3_3	431-442
	str S2345B8_v3_4	443-454
	str S2345B8_v3_5	455-466
	str S2345B8_v3_6	467-478
	str S2345B8_v4_3	479-490
	str S2345B8_v4_4	491-502
	str S2345B8_v4_5	503-514
	str S2345B8_v4_6	515-526
	str S2345B8_v5_3	527-538
	str S2345B8_v5_4	539-550
	str S2345B8_v5_5	551-562
	str S2345B8_v5_6	563-574
	str S2345B8_v6_3	575-586
	str S2345B8_v6_4	587-598
	str S2345B8_v6_5	599-610
	str S2345B8_v6_6	611-622
	
using "$pathin\WHCC202`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B8_v1_3	"Land-own";
la var S2345B8_v1_4	"Land-hired";
la var S2345B8_v1_5	"Land-net add";
la var S2345B8_v1_6	"Yearly-land-rent";
la var S2345B8_v2_3	"Build-own";
la var S2345B8_v2_4	"Build-hired";
la var S2345B8_v2_5	"Build-net add";
la var S2345B8_v2_6	"Yearly-build-rent";
la var S2345B8_v3_3	"Plant-own";
la var S2345B8_v3_4	"Plant-hired";
la var S2345B8_v3_5	"Plant-net add";
la var S2345B8_v3_6	"Yearly-plant-rent";
la var S2345B8_v4_3	"Transport-own";
la var S2345B8_v4_4	"Transport-hired";
la var S2345B8_v4_5	"Transport-net-addition";
la var S2345B8_v4_6	"Yearly-transport-rent";
la var S2345B8_v5_3	"Tools-own";
la var S2345B8_v5_4	"Tools-hired";
la var S2345B8_v5_5	"Tools-net-addition";
la var S2345B8_v5_6	"Yearly-tools-rent";
la var S2345B8_v6_3	"Total-assets-own";
la var S2345B8_v6_4	"Total-assets-hired";
la var S2345B8_v6_5	"Total-assets-net add";
la var S2345B8_v6_6	"Yearly-total-assets-rent";
la var weight       "Weighting coefficient" ;

la val sector sector;
la val state state;
la val svy_code svy_code;
la val enterp_type enterp_type;
la val subst_rsn subst_rsn;
la val BAG BAG;

order entid state;
sort entid;		
save "$pathout\WHCC202`i'_B8.dta", replace;
};

use "$pathout\WHCC202R_B8.dta", clear;
append using "$pathout\WHCC202U_B8.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk8.dta",replace;
erase "$pathout\WHCC202R_B8.dta";
erase "$pathout\WHCC202U_B8.dta";

***************************************************************;
* SCHEDULE 2.345 - Workfile2-Block 9                           ;
***************************************************************;

local workfile2 R U;

foreach i in `workfile2' {;

	drop _all;
	infix  
	str workfile_id	    1-2
	str flot	        3-7
	str round_schedule  8-10
	str ss_orig	        11
	str sector	        12
	str state_region    13-15
	str state	        13-14
	str district	    16-17
	str stratum	        18-19
	str sub_stratum	    20-21
	str sub_round	    22
	str sub_sample	    23
	str FSU_No	        24-28
	str segment	        29
	str BAG	            30
	str enterp_type	    31
	str enterp_no 		32-33
	str svy_code	    34
	str subst_rsn	    35
	str NSS	            36-38
	str NSC	            39-41
	str MLT		        42-51
	str NIC	            52-56
	str tab_cat	        57-58
	str S2345B9_v1_3	95-106
	str S2345B9_v1_4	107-118
	str S2345B9_v2_3	119-130
	str S2345B9_v2_4	131-142
	str S2345B9_v3_3	143-154
	str S2345B9_v3_4	155-166
	str S2345B9_v4_3	167-178
	str S2345B9_v4_4	179-190
	str S2345B9_v5_3	191-202
	str S2345B9_v5_4	203-214
	str S2345B9_v6_3	215-226
	str S2345B9_v6_4	227-238
	str S2345B9_v7_3	239-250
	str S2345B9_v7_4	251-262
	str S2345B9_v8_3	263-274
	str S2345B9_v8_4	275-286
	str S2345B9_v9_3	287-298
	str S2345B9_v9_4	299-310
	str S2345B9_v10_3	311-322
	str S2345B9_v10_4	323-334

using "$pathin\WHCC202`i'.DAT";

gen entid= sub_sample+FSU_No+segment+BAG+enterp_type+enterp_no;
destring *, replace;
format entid %12.0f;

gen weight=MLT/200 if NSC>NSS;
replace weight=MLT/100 if NSS==NSC;

la var workfile_id "Work-file id";
la var flot "Flot";
la var round_schedule "Round- Schedule Number";
la var ss_orig "Original sub_sample Code";
la var sector "Sector";
la var state_region "State-Region";
la var state "State";
la var district "District";
la var stratum "stratum";
la var sub_stratum "sub_stratum";
la var sub_round "Sub-round";
la var sub_sample "Sub-sample Code";
la var FSU_No "FSU Serial No.";
la var segment "Segment no.";
la var BAG "Broad Activity Group Code";
la var enterp_type "Enterprise type";
la var enterp_no  "Enterprise serial number";
la var entid "Enterprise id";
la var svy_code "Survey Code";
la var subst_rsn "Substitution Code";
la var NIC "National Industrial Classification Codes";
la var tab_cat "Tabulation Category";
la var S2345B9_v1_3	"Loan-amt-lendinst";
la var S2345B9_v1_4	"Yearly-loan-int.-lendinst";
la var S2345B9_v2_3	"Loan-amt-bank";
la var S2345B9_v2_4	"Yearly-loan-int.-bank";
la var S2345B9_v3_3	"Loan-amt-coop";
la var S2345B9_v3_4	"Yearly-loan-int.-coop";
la var S2345B9_v4_3	"Loan-amt.-agen";
la var S2345B9_v4_4	"Yearly-loan-int-agen";
la var S2345B9_v5_3	"Loan-amt-lender";
la var S2345B9_v5_4	"Yearly-loan-int-lender";
la var S2345B9_v6_3	"Loan-amt.-partner";
la var S2345B9_v6_4	"Yearly-loan-int.-partner";
la var S2345B9_v7_3	"Loan-amt.-contrac";
la var S2345B9_v7_4	"Yearly-loan-int.-contrac";
la var S2345B9_v8_3	"Loan-amt.-reltv";
la var S2345B9_v8_4	"Yearly-loan-int.-reltv";
la var S2345B9_v9_3	"Loan-amt.-other";
la var S2345B9_v9_4	"Yearly-loan-int.-other";
la var S2345B9_v10_3 "Loan-amt.-total";
la var S2345B9_v10_4 "Yearly-loan-int.total";
la var weight "Weighting coefficient" ;

la val sector sector;
la val state state;
la val svy_code svy_code;
la val enterp_type enterp_type;
la val subst_rsn subst_rsn;
la val BAG BAG;

order entid state;
sort entid;		
save "$pathout\WHCC202`i'_B9.dta", replace;
};

use "$pathout\WHCC202R_B9.dta", clear;
append using "$pathout\WHCC202U_B9.dta";
order entid state;
sort entid;	
compress;
saveold "$pathout\NSS57_Sch2345_bk9.dta",replace;
erase "$pathout\WHCC202R_B9.dta";
erase "$pathout\WHCC202U_B9.dta";
