Project

General

Profile

Support #2066 » 2. 2066 (option2).log

 
1
----------------------------------------------------------------------------------
2
      name:  <unnamed>
3
       log:  D:\USF\issues\2066\2066 (option2).log
4
  log type:  text
5
 opened on:   7 Mar 2024, 21:49:13
6

    
7
. /*  Note: The data file produced will be at the individual level and cover all a
8
> ges, irrespective of the variables requested. 
9
/ is not a valid command name
10
r(199);
11

    
12
. 
13
.  In this current version of the tool, it is not possible to select variables by 
14
> wave - though you may edit the code below to do so. */
15
command In is unrecognized
16
r(199);
17

    
18
. 
19
. 
20
. 
21
. /*******************************************************************************
22
> *********
23
/ is not a valid command name
24
r(199);
25

    
26
. 
27
. * Sample Code for your request:  7a400d9a784848fd9e94ac517185bf40       *
28

    
29
. 
30
. ********************************************************************************
31
> *********/
32

    
33
. 
34
. clear all
35

    
36
. 
37
. set more off
38

    
39
. 
40
. 
41
. 
42
. // Replace "where" with the filepath of the working folder (where any temporary 
43
> files created by this programme will be stored)   eg:  c:\ukhls\temp
44
/ is not a valid command name
45
r(199);
46

    
47
. 
48
. cd "where" 
49
unable to change to where
50
r(170);
51

    
52
. 
53
. 
54
. 
55
. // Replace "where" with the folderpath where the data has been downloaded and un
56
> zipped   eg:   c:\ukhls_data\UKDA-6614-stata\stata\stata13_se\ukhls
57
/ is not a valid command name
58
r(199);
59

    
60
. 
61
. global ukhls "where\UKDA-6614-stata\stata\stata13_se\ukhls"
62

    
63
. 
64
. 
65
. 
66
. // Replace "where" with the filepath of the folder where you want to store the f
67
> inal dataset produced by this programme.  eg:  c:\ukhls\results
68
/ is not a valid command name
69
r(199);
70

    
71
. 
72
. global outputpath "where"
73

    
74
. 
75
. 
76
. 
77
. // The file produced by this programme will be named as below. If you want to ch
78
> ange the name do it here.
79
/ is not a valid command name
80
r(199);
81

    
82
. 
83
. local outputfilename "UKHLS_wide_hij"
84

    
85
. 
86
. 
87
. 
88
. // By default the data will be extracted from the waves whose letter prefixes ar
89
> e written below, and merged. If you want to a different selection of waves, make
90
>  the change here
91
/ is not a valid command name
92
r(199);
93

    
94
. 
95
. local allWaves = "h i j"
96

    
97
. 
98
. 
99
. 
100
. // These variables from the indall files will be included. These include some ke
101
> y variables as determined by us PLUS any variables requested by you. 
102
/ is not a valid command name
103
r(199);
104

    
105
. 
106
. local indallvars "age_dv country ethn_dv gor_dv hhsize hidp mastat_dv nchild_dv 
107
> pidp pno psnen01_lw psnen01_xw psnen91_lw psnen91_xw psnen99_lw psnen99_xw psnen
108
> ub_lw psnenub_xw psnenui_lw psnenui_xw psnenus_lw psnenus_xw psu racel_dv sex_dv
109
>  strata urban_dv"
110

    
111
. 
112
. 
113
. 
114
. // These variables from the indresp files will be included. These include some k
115
> ey variables as determined by us PLUS any variables requested by you. 
116
/ is not a valid command name
117
r(199);
118

    
119
. 
120
. local indvars "age_dv country ethn_dv gor_dv hhsize hhtype_dv hidp ind5mus_lw in
121
> d5mus_xw indbd91_lw indbdub_lw indin01_lw indin01_xw indin91_lw indin91_xw indin
122
> 99_lw indin99_xw indinub_lw indinub_xw indinui_lw indinui_xw indinus_lw indinus_
123
> xw indns91_lw indnsub_lw indpxub_lw indpxub_xw indpxui_lw indpxui_xw indpxus_lw 
124
> indpxus_xw indscub_lw indscub_xw indscui_lw indscui_xw indscus_lw indscus_xw jbb
125
> gy jbsat jbsemp jbstat jsboss jspart jssize mastat_dv nchild_dv pidp pno psu rac
126
> el_dv sclfsato sex_dv strata tenure_dv ukborn urban_dv wkaut1 wkaut2 wkaut3 wkau
127
> t4 wkaut5"
128

    
129
. 
130
. 
131
. 
132
. // These variables from the child files will be included. These include some key
133
>  variables as determined by us PLUS any variables requested by you. 
134
/ is not a valid command name
135
r(199);
136

    
137
. 
138
. local chvars "age_dv chddvub_lw chddvub_xw chddvui_lw chddvui_xw country gor_dv 
139
> hhsize hidp pidp pno psnen01_lw psnen91_lw psnenub_lw psnenub_xw psnenui_lw psne
140
> nui_xw psnenus_lw psnenus_xw psu sex_dv strata urban_dv"
141

    
142
. 
143
. 
144
. 
145
. // These variables from the hhresp files will be included. These include some ke
146
> y variables as determined by us PLUS any variables requested by you. 
147
/ is not a valid command name
148
r(199);
149

    
150
. 
151
. local hhvars "country fihhmnnet1_dv gor_dv hhden01_xw hhden91_xw hhden99_xw hhde
152
> nub_xw hhdenui_xw hhdenus_xw hhsize hhtype_dv hidp ieqmoecd_dv nkids_dv psu stra
153
> ta tenure_dv urban_dv"
154

    
155
. 
156
. 
157
. 
158
. // These variables from the youth files will be included. These include some key
159
>  variables as determined by us PLUS any variables requested by you. 
160
/ is not a valid command name
161
r(199);
162

    
163
. 
164
. local youthvars "age_dv country ethn_dv gor_dv hidp pidp pno psu racel_dv sex_dv
165
>  strata urban_dv ythscub_xw ythscui_xw ythscus_xw"
166

    
167
. 
168
. 
169
. 
170
. 
171
. 
172
. ////////////////////////////////////////////////////////////////////////////////
173
> /////////////////////////////////////////////////////////////////////////
174
/ is not a valid command name
175
r(199);
176

    
177
. 
178
. // Anything below this line should not be changed! Any changes to the selection 
179
> of variables and waves, and location of folders, should be made above. //
180
/ is not a valid command name
181
r(199);
182

    
183
. 
184
. ////////////////////////////////////////////////////////////////////////////////
185
> /////////////////////////////////////////////////////////////////////////
186
/ is not a valid command name
187
r(199);
188

    
189
. 
190
. 
191
. 
192
. // this program returns all variable names with the wave prefix
193
/ is not a valid command name
194
r(199);
195

    
196
. 
197
. program define getVars, rclass
198
  1. 
199
.     version 14.0
200
  2. 
201
. if ("`1'" != "") {
202
  3. 
203
. local wavemyvars = " `1'"
204
  4. 
205
. local wavemyvars = subinstr("`wavemyvars'"," "," `2'_",.)
206
  5. 
207
. local wavemyvars = substr("`wavemyvars'",2,.)
208
  6. 
209
. }
210
  7. 
211
. else local wavemyvars = ""
212
  8. 
213
. return local fixedVars "`wavemyvars'"
214
  9. 
215
. end
216

    
217
. 
218
. 
219
. 
220
. // this program to returns  which variables exist in this wave
221
/ is not a valid command name
222
r(199);
223

    
224
. 
225
. program define getExistingVars, rclass
226
  1. 
227
.     version 14.0
228
  2. 
229
. local all = ""
230
  3. 
231
. foreach var in `1' {
232
  4. 
233
. capture confirm variable `var'
234
  5. 
235
. if !_rc {
236
  6. 
237
. local all = "`all' `var'"
238
  7. 
239
. }
240
  8. 
241
. }
242
  9. 
243
. return local existingVars "`all'"
244
 10. 
245
. end  
246

    
247
. 
248
. 
249
. 
250
. //loop through each wave
251
/ is not a valid command name
252
r(199);
253

    
254
. 
255
. foreach wave in `allWaves' {
256
  2. 
257
. // find the wave number
258
  3. 
259
. local waveno=strpos("abcdefghijklmnopqrstuvwxyz","`wave'")
260
  4. 
261
. 
262
. 
263
. // find the wave household vars
264
  5. 
265
. getVars "`hhvars'" `wave'
266
  6. 
267
. local wavehhvars = "`r(fixedVars)'"
268
  7. 
269
. 
270
. 
271
. // find the wave individual vars
272
  8. 
273
. getVars "`indvars'" `wave'
274
  9. 
275
. local waveindvars = "`r(fixedVars)'"
276
 10. 
277
. 
278
. 
279
. // find the wave all individual vars
280
 11. 
281
. getVars "`indallvars'" `wave'
282
 12. 
283
. local waveindallvars = "`r(fixedVars)'"
284
 13. 
285
. 
286
. 
287
. // find the wave child vars
288
 14. 
289
. getVars "`chvars'" `wave'
290
 15. 
291
. local wavechvars = "`r(fixedVars)'"
292
 16. 
293
. 
294
. 
295
. // find the wave youth vars
296
 17. 
297
. getVars "`youthvars'" `wave'
298
 18. 
299
. local waveyouthvars = "`r(fixedVars)'"
300
 19. 
301
. 
302
. 
303
. // open the the household level file with the required variables
304
 20. 
305
. use "$ukhls/`wave'_hhresp", clear
306
 21. 
307
. getExistingVars "`wave'_hidp `wavehhvars'"
308
 22. 
309
. keep `r(existingVars)'
310
 23. 
311
. 
312
. 
313
. // if only household variables are required, skip this part and return all house
314
> holds
315
 24. 
316
. if ("`indvars'" != "" || "`chvars'" != "" || "`youthvars'" != "") {
317
 25. 
318
. // if any individual variable is required, first  merge INDALL keeping the pipd 
319
> (and possibly some default variables?), so that other files can merge on it.
320
 26. 
321
. merge 1:m `wave'_hidp using "$ukhls/`wave'_indall"
322
 27. 
323
. drop _merge
324
 28. 
325
. // drop loose households with no individuals
326
 29. 
327
. drop if (pidp == .)
328
 30. 
329
. 
330
. 
331
. // keep only variables that were requested and exist in this wave
332
 31. 
333
. getExistingVars "pidp `wave'_hidp `wavehhvars' `waveindallvars'"
334
 32. 
335
. keep `r(existingVars)'
336
 33. 
337
. 
338
. 
339
. // add any requested individual variables
340
 34. 
341
. if ("`indvars'" != "") {
342
 35. 
343
. merge 1:1 pidp using "$ukhls/`wave'_indresp"
344
 36. 
345
. drop _merge
346
 37. 
347
. // keep only variables that were requested and exist in this wave
348
 38. 
349
. getExistingVars "pidp `wave'_hidp `wavehhvars' `waveindvars' `waveyouthvars' `wa
350
> vechvars' `waveindallvars'"
351
 39. 
352
. keep `r(existingVars)'
353
 40. 
354
. }
355
 41. 
356
. // add any requested youth variables
357
 42. 
358
. if ("`waveyouthvars'" != "") {
359
 43. 
360
. merge 1:1 pidp using "$ukhls/`wave'_youth"
361
 44. 
362
. drop _merge
363
 45. 
364
. // keep only variables that were requested and exist in this wave
365
 46. 
366
. getExistingVars "pidp `wave'_hidp `wavehhvars' `waveindvars' `waveyouthvars' `wa
367
> vechvars' `waveindallvars'"
368
 47. 
369
. keep `r(existingVars)'
370
 48. 
371
. }
372
 49. 
373
. // add any requested child variables
374
 50. 
375
. if ("`wavechvars'" != "") {
376
 51. 
377
. merge 1:1 pidp using "$ukhls/`wave'_child"
378
 52. 
379
. drop _merge
380
 53. 
381
. // keep only variables that were requested and exist in this wave
382
 54. 
383
. getExistingVars "pidp `wave'_hidp `wavehhvars' `waveindvars' `waveyouthvars' `wa
384
> vechvars' `waveindallvars'"
385
 55. 
386
. keep `r(existingVars)'
387
 56. 
388
. }
389
 57. 
390
. }
391
 58. 
392
. 
393
. 
394
. // save the file that was created
395
 59. 
396
. save temp_`wave', replace
397
 60. 
398
. }
399
/ is not a valid command name
400
r(199);
401

    
402
. 
403
. 
404
. 
405
. local firstWave = substr("`allWaves'", 1, 1)
406

    
407
. 
408
. 
409
. 
410
. // open the individual level file for wave 1 containing the variables to use
411
/ is not a valid command name
412
r(199);
413

    
414
. 
415
. local firstvar = subinstr("`joinvars'","#","`firstWave'",.)
416

    
417
. 
418
. use pidp `firstvar' using "temp_`firstWave'", clear
419
file temp_h.dta not found
420
r(601);
421

    
422
. 
423
. 
424
. 
425
. //sort by pidp and save
426
/ is not a valid command name
427
r(199);
428

    
429
. 
430
. sort pidp
431
no variables defined
432
r(111);
433

    
434
. 
435
. save "$outputpath/`outputfilename'", replace
436
no variables defined
437
r(111);
438

    
439
. 
440
. 
441
. 
442
. // loop through the remaining waves
443
/ is not a valid command name
444
r(199);
445

    
446
. 
447
. local remainingWaves = substr("`allWaves'", 1, .)
448

    
449
. 
450
. 
451
. 
452
. 
453
. 
454
. foreach wave in `remainingWaves' {
455
  2. 
456
. // open the individual level file for that wave
457
  3. 
458
. use * using "temp_`wave'", clear
459
  4. 
460
. 
461
. 
462
. // sort by pidp
463
  5. 
464
. sort pidp
465
  6. 
466
. 
467
. 
468
. // merge with the file previously saved
469
  7. 
470
. merge 1:1 pidp using "$outputpath/`outputfilename'"
471
  8. 
472
. drop _merge
473
  9. 
474
. 
475
. 
476
. // sort by pidp
477
 10. 
478
. sort pidp
479
 11. 
480
. 
481
. 
482
.         // save the file to be used in the next merge
483
 12. 
484
.         order pidp, first
485
 13. 
486
. save "$outputpath/`outputfilename'", replace
487
 14. 
488
. }
489
/ is not a valid command name
490
r(199);
491

    
492
. 
493
. 
494
. 
495
. // erase temporary files
496
/ is not a valid command name
497
r(199);
498

    
499
. 
500
. foreach w in `allWaves' {
501
  2. 
502
. erase temp_`w'.dta
503
  3. 
504
. }
505
file temp_h.dta not found
506
r(601);
507

    
508
. log close
509
      name:  <unnamed>
510
       log:  D:\USF\issues\2066\2066 (option2).log
511
  log type:  text
512
 closed on:   7 Mar 2024, 21:49:40
513
----------------------------------------------------------------------------------
(5-5/6)