Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Consumer Expenditure Survey - file __________ not found error

    What is the problem in this code, the file mtbi061x.dta is available in the working directory, but I still get the error.


    . global data_path "C:\Users\user\OneDrive\Desktop\aggregate2"

    .
    . * The uccs in the mtbi files are basic elements composing the categories of fmli.
    . * When you sum up uccs which compose the categories of fmli according to the formulas described on the variables s
    > heet in "ce_pumd_interview_diary_dictionary.xlsx".
    . * Theoretical the sums of uccs in mtbi should be equal to the values of fmli. However, there could be some discrep
    > ancies in the results.
    . * The following 3 categories may have discrepancies in their results because neither there is a ucc nor a formula:
    > VRNTLOCQ, HLTHINCQ, RETPENCQ.
    . * The expenses of specific items in mtbi files will be divided into the current quarter and the previous quarter.
    . * The data organized from the above will be merged with fmli files.
    . * Calculate the weighted average by inc_quantile, age and nfamily.
    .
    . * How to turn off "more" automatically.
    . set more off, permanently
    (set more preference recorded)

    .
    . ************************************************** ******************************
    . ***** Classify every ucc into the current quarter and the previous quarter *****
    . ************************************************** ******************************
    .
    .
    .
    . * Exclude the uccs which expires before 2000.
    . * It takes about 30 hrs to process this part.
    . * Exclude the overlapping uccs as well as the uccs with the same code description.
    . foreach i in 002120 190901 190902 190903 190904 200900 210110 210210 210310 210901 220121 220211 220311 220313 220
    > 512 220513 ///
    > 220611 220612 220615 220901 230112 230113 230114 230115 230117 230118 230141 230150 230151 230152 230901 240111 2
    > 40113 240121 ///
    > 240123 240211 240212 240213 240214 240221 240311 240321 250111 250112 250113 250114 250211 250212 250213 250214 2
    > 50223 250911 ///
    > 250912 250914 260111 260112 260113 260114 260211 260212 260213 260214 270102 270104 270106 270211 270212 270213 2
    > 70214 270310 ///
    > 270311 270411 270412 270413 270414 270901 270902 270903 280110 280120 280140 280210 280220 290110 290120 290210 2
    > 90310 290320 ///
    > 290410 290420 290430 290440 300111 300112 300216 300217 300311 300312 300321 300322 300331 300332 300411 300412 3
    > 10140 310210 ///
    > 310220 310231 310232 310240 310243 310314 310316 310333 310334 310340 310350 310400 320111 320120 320130 320150 3
    > 20221 320232 ///
    > 320233 320330 320345 320370 320410 320420 320511 320512 320521 320522 320611 320624 320631 320901 320902 320903 3
    > 20904 330511 ///
    > 340210 340310 340410 340420 340510 340520 340530 340610 340620 340630 340901 340902 340903 340904 340905 340906 3
    > 40907 340908 ///
    > 340910 340911 340914 340915 350110 360110 360120 360210 360311 360312 360320 360330 360350 360420 360513 360901 3
    > 60902 370110 ///
    > 370125 370211 370212 370213 370220 370311 370314 370902 370903 370904 380110 380210 380311 380315 380320 380333 3
    > 80340 380410 ///
    > 380420 380430 380510 380901 380902 380903 390110 390120 390210 390223 390230 390310 390321 390322 390901 390902 4
    > 00110 400210 ///
    > 400220 400310 410110 410120 410130 410140 410901 420115 430110 430120 430130 440110 440120 440130 440140 440150 4
    > 40210 440900 ///
    > 450110 450116 450210 450216 450220 450226 450350 450351 450352 450353 450354 460110 460116 460901 460902 460907 4
    > 60908 470111 ///
    > 470112 470113 470211 470212 470220 470311 480110 480213 480216 490110 490300 490311 490312 490313 490314 490318 4
    > 90501 490900 ///
    > 500110 510110 510901 510902 520110 520310 520410 520516 520517 520531 520532 520541 520542 520550 520901 520902 5
    > 20904 520905 ///
    > 520907 530110 530210 530311 530312 530411 530412 530510 530901 530902 540000 550110 550320 550330 550340 560110 5
    > 60210 560310 ///
    > 560330 560400 560410 560420 570111 570220 570230 570240 570901 570903 580115 580116 580311 580312 580400 580401 5
    > 80402 580411 ///
    > 580412 580421 580422 580431 580432 580901 580903 580904 580905 580906 580907 580908 580909 590220 590230 590310 5
    > 90410 600110 ///
    > 600121 600122 600127 600128 600132 600138 600141 600142 600143 600144 600210 600310 600410 600420 600430 600901 6
    > 00902 610110 ///
    > 610120 610130 610140 610210 610230 610320 610900 620111 620112 620114 620115 620121 620122 620212 620213 620214 6
    > 20215 620216 ///
    > 620221 620222 620310 620320 620330 620410 620420 620903 620904 620905 620906 620908 620909 620912 620917 620918 6
    > 20919 620921 ///
    > 620922 620926 620930 630110 630210 640130 640420 640430 650310 660110 660210 660410 660901 660902 670110 670210 6
    > 70310 670410 ///
    > 670901 670902 670903 680110 680140 680210 680220 680310 680320 680901 680902 680904 680905 690111 690113 690114 6
    > 90116 690117 ///
    > 690118 690119 690120 690230 690244 690245 690310 690320 690330 690340 690350 700110 790210 790240 790330 790410 7
    > 90420 790430 ///
    > 790600 790610 790611 790620 790630 790640 790690 790710 790730 790810 790830 790910 790920 790930 790940 800111 8
    > 00121 800700 ///
    > 800710 800721 800804 800811 800821 800831 800841 800851 800861 810101 810102 810301 810302 810400 820101 820102 8
    > 20202 820301 ///
    > 820302 830101 830102 830201 830202 830203 830204 830301 830302 830303 830304 840101 840102 850100 850200 850300 8
    > 60100 860200 ///
    > 860301 860302 860400 860500 860600 860700 870101 870102 870103 870104 870201 870202 870203 870204 870301 870302 8
    > 70303 870304 ///
    > 870401 870403 870404 870501 870502 870503 870504 870605 870606 870607 870701 870702 870703 870704 870801 870802 8
    > 70803 880110 ///
    > 880120 880210 880220 880320 900002 910042 910050 910101 910102 910103 910104 910105 910107 950024 990900 990920 9
    > 90930 990950 ///
    > 320632 990940 800803 250221 250904 820201 220321 490502 250222 250901 250902 310110 310120 310130 310341 310342 5
    > 70110 570210 ///
    > 590111 590112 590211 590212 690220 250903 660900 270103 790220 790230 790310 790320 270904 320210 320231 360511 3
    > 60512 370312 ///
    > 370313 380331 380332 390221 390222 910100 790820 790950 950030 310230 690112 320623 450414 220616 230133 230134 3
    > 20163 620916 ///
    > 250913 006001 006002 450311 450312 450411 450412 870608 230121 270101 280130 280230 280900 300211 300212 300221 3
    > 00222 310311 ///
    > 310313 310320 320220 320310 320320 320340 320350 320360 320621 320622 340211 340212 360340 360410 370120 370130 3
    > 80312 380313 ///
    > 420110 420120 450310 450313 450314 450410 450413 480214 490211 490212 490221 490231 490232 490319 490411 490412 4
    > 90413 520511 ///
    > 520512 520521 520522 580111 580112 580113 580114 620113 620211 690210 690241 690242 710110 870804 860800 480212 4
    > 80215 520560 ///
    > 690115 270105 006009 006010 870402 660310 240223 910106 {
    2.
    . forvalues j=6/8 {
    3.
    . local x=`j'+1
    4.
    . use ${datapath}\mtbi0`j'1x, replace
    5.
    . * code description (removing the overlapping uccs)
    . replace ucc="210901" if ucc=="210902"
    6. replace ucc="220121" if ucc=="220122"
    7. replace ucc="220211" if ucc=="220212"
    8. replace ucc="220311" if ucc=="220312"
    9. replace ucc="220313" if ucc=="220314"
    10. replace ucc="220901" if ucc=="220902"
    11. replace ucc="230141" if ucc=="230142"
    12. replace ucc="230901" if ucc=="230902"
    13. replace ucc="240111" if ucc=="240112"
    14. replace ucc="240121" if ucc=="240122"
    15. replace ucc="240121" if ucc=="240123"
    16. replace ucc="240221" if ucc=="240222"
    17. replace ucc="240311" if ucc=="240312"
    18. replace ucc="240311" if ucc=="240313"
    19. replace ucc="240321" if ucc=="240322"
    20. replace ucc="240321" if ucc=="240323"
    21. replace ucc="320611" if ucc=="320612"
    22. replace ucc="320611" if ucc=="320613"
    23. replace ucc="320624" if ucc=="320625"
    24. replace ucc="320624" if ucc=="320626"
    25. replace ucc="340911" if ucc=="340912"
    26. replace ucc="580431" if ucc=="580441"
    27. replace ucc="580432" if ucc=="580442"
    28. replace ucc="580909" if ucc=="580910"
    29. replace ucc="880110" if ucc=="880310"
    30. replace ucc="220111" if ucc=="220112"
    31. replace ucc="320632" if ucc=="320633"
    32. replace ucc="230121" if ucc=="230122"
    33. replace ucc="230121" if ucc=="230123"
    34.
    . * If and else command to ignore the uccs not mentioned above
    . gen tem=1 if ucc=="`i'"
    35. replace tem=0 if tem==.
    36. egen tem_max=max(tem)
    37. if tem_max>0 {
    38.
    . keep if ucc=="`i'"
    39.
    . * For the 2nd, the 3rd and the 4th quarter, use both current and previous values.
    . * For the 1st quarter, you only need previous values
    . gen current=1 if ref_mo=="01" | ref_mo=="02" | ref_mo=="03"
    40. replace current=0 if current==.
    41.
    . sort newid
    42. bysort newid: egen var_`i'_cur=sum(cost*current)
    43.
    . drop if newid==newid[_n-1]
    44. keep newid var_`i'_cur
    45.
    . save us_`i'_200`j'q1x, replace
    46.
    . }
    47.
    . else {
    48.
    . keep newid
    49. sort newid
    50. drop if newid==newid[_n-1]
    51. gen var_`i'_cur=.
    52.
    . save us_`i'_200`j'q1x, replace
    53.
    . }
    54.
    .
    .
    . use ${datapath}\mtbi0`j'2, replace
    55.
    . * code description (removing the overlapping uccs)
    . replace ucc="210901" if ucc=="210902"
    56. replace ucc="220121" if ucc=="220122"
    57. replace ucc="220211" if ucc=="220212"
    58. replace ucc="220311" if ucc=="220312"
    59. replace ucc="220313" if ucc=="220314"
    60. replace ucc="220901" if ucc=="220902"
    61. replace ucc="230141" if ucc=="230142"
    62. replace ucc="230901" if ucc=="230902"
    63. replace ucc="240111" if ucc=="240112"
    64. replace ucc="240121" if ucc=="240122"
    65. replace ucc="240121" if ucc=="240123"
    66. replace ucc="240221" if ucc=="240222"
    67. replace ucc="240311" if ucc=="240312"
    68. replace ucc="240311" if ucc=="240313"
    69. replace ucc="240321" if ucc=="240322"
    70. replace ucc="240321" if ucc=="240323"
    71. replace ucc="320611" if ucc=="320612"
    72. replace ucc="320611" if ucc=="320613"
    73. replace ucc="320624" if ucc=="320625"
    74. replace ucc="320624" if ucc=="320626"
    75. replace ucc="340911" if ucc=="340912"
    76. replace ucc="580431" if ucc=="580441"
    77. replace ucc="580432" if ucc=="580442"
    78. replace ucc="580909" if ucc=="580910"
    79. replace ucc="880110" if ucc=="880310"
    80. replace ucc="220111" if ucc=="220112"
    81. replace ucc="320632" if ucc=="320633"
    82. replace ucc="230121" if ucc=="230122"
    83. replace ucc="230121" if ucc=="230123"
    84.
    . gen tem=1 if ucc=="`i'"
    85. replace tem=0 if tem==.
    86. egen tem_max=max(tem)
    87. if tem_max>0 {
    88.
    . keep if ucc=="`i'"
    89.
    . gen current=1 if ref_mo=="04" | ref_mo=="05" | ref_mo=="06"
    90. replace current=0 if current==.
    91.
    . gen previous=1 if ref_mo=="01" | ref_mo=="02" | ref_mo=="03"
    92. replace previous=0 if previous==.
    93.
    . sort newid
    94. bysort newid: egen var_`i'_cur=sum(cost*current)
    95. bysort newid: egen var_`i'_pre=sum(cost*previous)
    96.
    . drop if newid==newid[_n-1]
    97. keep newid var_`i'_cur var_`i'_pre
    98.
    . save us_`i'_200`j'q2, replace
    99.
    . }
    100.
    . else {
    101.
    . keep newid
    102. sort newid
    103. drop if newid==newid[_n-1]
    104. gen var_`i'_cur=.
    105. gen var_`i'_pre=.
    106.
    . save us_`i'_200`j'q2, replace
    107.
    . }
    108.
    .
    .
    . use ${datapath}\mtbi0`j'3, replace
    109.
    . * code description (removing the overlapping uccs)
    . replace ucc="210901" if ucc=="210902"
    110. replace ucc="220121" if ucc=="220122"
    111. replace ucc="220211" if ucc=="220212"
    112. replace ucc="220311" if ucc=="220312"
    113. replace ucc="220313" if ucc=="220314"
    114. replace ucc="220901" if ucc=="220902"
    115. replace ucc="230141" if ucc=="230142"
    116. replace ucc="230901" if ucc=="230902"
    117. replace ucc="240111" if ucc=="240112"
    118. replace ucc="240121" if ucc=="240122"
    119. replace ucc="240121" if ucc=="240123"
    120. replace ucc="240221" if ucc=="240222"
    121. replace ucc="240311" if ucc=="240312"
    122. replace ucc="240311" if ucc=="240313"
    123. replace ucc="240321" if ucc=="240322"
    124. replace ucc="240321" if ucc=="240323"
    125. replace ucc="320611" if ucc=="320612"
    126. replace ucc="320611" if ucc=="320613"
    127. replace ucc="320624" if ucc=="320625"
    128. replace ucc="320624" if ucc=="320626"
    129. replace ucc="340911" if ucc=="340912"
    130. replace ucc="580431" if ucc=="580441"
    131. replace ucc="580432" if ucc=="580442"
    132. replace ucc="580909" if ucc=="580910"
    133. replace ucc="880110" if ucc=="880310"
    134. replace ucc="220111" if ucc=="220112"
    135. replace ucc="320632" if ucc=="320633"
    136. replace ucc="230121" if ucc=="230122"
    137. replace ucc="230121" if ucc=="230123"
    138.
    . gen tem=1 if ucc=="`i'"
    139. replace tem=0 if tem==.
    140. egen tem_max=max(tem)
    141. if tem_max>0 {
    142.
    . keep if ucc=="`i'"
    143.
    . gen current=1 if ref_mo=="07" | ref_mo=="08" | ref_mo=="09"
    144. replace current=0 if current==.
    145.
    . gen previous=1 if ref_mo=="04" | ref_mo=="05" | ref_mo=="06"
    146. replace previous=0 if previous==.
    147.
    . sort newid
    148. bysort newid: egen var_`i'_cur=sum(cost*current)
    149. bysort newid: egen var_`i'_pre=sum(cost*previous)
    150.
    . drop if newid==newid[_n-1]
    151. keep newid var_`i'_cur var_`i'_pre
    152.
    . save us_`i'_200`j'q3, replace
    153.
    . }
    154.
    . else {
    155.
    . keep newid
    156. sort newid
    157. drop if newid==newid[_n-1]
    158. gen var_`i'_cur=.
    159. gen var_`i'_pre=.
    160.
    . save us_`i'_200`j'q3, replace
    161.
    . }
    162.
    .
    .
    . use ${datapath}\mtbi0`j'4, replace
    163.
    . * code description (removing the overlapping uccs)
    . replace ucc="210901" if ucc=="210902"
    164. replace ucc="220121" if ucc=="220122"
    165. replace ucc="220211" if ucc=="220212"
    166. replace ucc="220311" if ucc=="220312"
    167. replace ucc="220313" if ucc=="220314"
    168. replace ucc="220901" if ucc=="220902"
    169. replace ucc="230141" if ucc=="230142"
    170. replace ucc="230901" if ucc=="230902"
    171. replace ucc="240111" if ucc=="240112"
    172. replace ucc="240121" if ucc=="240122"
    173. replace ucc="240121" if ucc=="240123"
    174. replace ucc="240221" if ucc=="240222"
    175. replace ucc="240311" if ucc=="240312"
    176. replace ucc="240311" if ucc=="240313"
    177. replace ucc="240321" if ucc=="240322"
    178. replace ucc="240321" if ucc=="240323"
    179. replace ucc="320611" if ucc=="320612"
    180. replace ucc="320611" if ucc=="320613"
    181. replace ucc="320624" if ucc=="320625"
    182. replace ucc="320624" if ucc=="320626"
    183. replace ucc="340911" if ucc=="340912"
    184. replace ucc="580431" if ucc=="580441"
    185. replace ucc="580432" if ucc=="580442"
    186. replace ucc="580909" if ucc=="580910"
    187. replace ucc="880110" if ucc=="880310"
    188. replace ucc="220111" if ucc=="220112"
    189. replace ucc="320632" if ucc=="320633"
    190. replace ucc="230121" if ucc=="230122"
    191. replace ucc="230121" if ucc=="230123"
    192.
    . gen tem=1 if ucc=="`i'"
    193. replace tem=0 if tem==.
    194. egen tem_max=max(tem)
    195. if tem_max>0 {
    196.
    . keep if ucc=="`i'"
    197.
    . gen current=1 if ref_mo=="10" | ref_mo=="11" | ref_mo=="12"
    198. replace current=0 if current==.
    199.
    . gen previous=1 if ref_mo=="07" | ref_mo=="08" | ref_mo=="09"
    200. replace previous=0 if previous==.
    201.
    . sort newid
    202. bysort newid: egen var_`i'_cur=sum(cost*current)
    203. bysort newid: egen var_`i'_pre=sum(cost*previous)
    204.
    . drop if newid==newid[_n-1]
    205. keep newid var_`i'_cur var_`i'_pre
    206.
    . save us_`i'_200`j'q4, replace
    207.
    . }
    208.
    . else {
    209.
    . keep newid
    210. sort newid
    211. drop if newid==newid[_n-1]
    212. gen var_`i'_cur=.
    213. gen var_`i'_pre=.
    214.
    . save us_`i'_200`j'q4, replace
    215.
    . }
    216.
    .
    .
    . use ${datapath}\mtbi0`x'1, replace
    217.
    . * code description (removing the overlapping uccs)
    . replace ucc="210901" if ucc=="210902"
    218. replace ucc="220121" if ucc=="220122"
    219. replace ucc="220211" if ucc=="220212"
    220. replace ucc="220311" if ucc=="220312"
    221. replace ucc="220313" if ucc=="220314"
    222. replace ucc="220901" if ucc=="220902"
    223. replace ucc="230141" if ucc=="230142"
    224. replace ucc="230901" if ucc=="230902"
    225. replace ucc="240111" if ucc=="240112"
    226. replace ucc="240121" if ucc=="240122"
    227. replace ucc="240121" if ucc=="240123"
    228. replace ucc="240221" if ucc=="240222"
    229. replace ucc="240311" if ucc=="240312"
    230. replace ucc="240311" if ucc=="240313"
    231. replace ucc="240321" if ucc=="240322"
    232. replace ucc="240321" if ucc=="240323"
    233. replace ucc="320611" if ucc=="320612"
    234. replace ucc="320611" if ucc=="320613"
    235. replace ucc="320624" if ucc=="320625"
    236. replace ucc="320624" if ucc=="320626"
    237. replace ucc="340911" if ucc=="340912"
    238. replace ucc="580431" if ucc=="580441"
    239. replace ucc="580432" if ucc=="580442"
    240. replace ucc="580909" if ucc=="580910"
    241. replace ucc="880110" if ucc=="880310"
    242. replace ucc="220111" if ucc=="220112"
    243. replace ucc="320632" if ucc=="320633"
    244. replace ucc="230121" if ucc=="230122"
    245. replace ucc="230121" if ucc=="230123"
    246.
    . gen tem=1 if ucc=="`i'"
    247. replace tem=0 if tem==.
    248. egen tem_max=max(tem)
    249. if tem_max>0 {
    250.
    . keep if ucc=="`i'"
    251.
    . gen previous=1 if ref_mo=="10" | ref_mo=="11" | ref_mo=="12"
    252. replace previous=0 if previous==.
    253.
    . sort newid
    254. bysort newid: egen var_`i'_pre=sum(cost*previous)
    255.
    . drop if newid==newid[_n-1]
    256. keep newid var_`i'_pre
    257.
    . save us_`i'_200`x'q1, replace
    258.
    . }
    259.
    . else {
    260.
    . keep newid
    261. sort newid
    262. drop if newid==newid[_n-1]
    263. gen var_`i'_pre=.
    264.
    . save us_`i'_200`x'q1, replace
    265.
    . }
    266.
    .
    .
    . }
    267.
    .
    .
    . ************************************************** ******************************
    .
    .
    .
    . use ${datapath}\mtbi091x, replace
    268.
    . gen tem=1 if ucc=="`i'"
    269. replace tem=0 if tem==.
    270. egen tem_max=max(tem)
    271. if tem_max>0 {
    272.
    . keep if ucc=="`i'"
    273.
    . gen current=1 if ref_mo=="01" | ref_mo=="02" | ref_mo=="03"
    274. replace current=0 if current==.
    275.
    . sort newid
    276. bysort newid: egen var_`i'_cur=sum(cost*current)
    277.
    . drop if newid==newid[_n-1]
    278. keep newid var_`i'_cur var_`i'_pre
    279.
    . save us_`i'_2009q1x, replace
    280.
    . }
    281.
    . else {
    282.
    . keep newid
    283. sort newid
    284. drop if newid==newid[_n-1]
    285. gen var_`i'_cur=.
    286.
    . save us_`i'_2009q1x, replace
    287.
    . }
    288.
    .
    .
    . use ${datapath}\mtbi092, replace
    289.
    . gen tem=1 if ucc=="`i'"
    290. replace tem=0 if tem==.
    291. egen tem_max=max(tem)
    292. if tem_max>0 {
    293.
    . keep if ucc=="`i'"
    294.
    . gen current=1 if ref_mo=="04" | ref_mo=="05" | ref_mo=="06"
    295. replace current=0 if current==.
    296.
    . gen previous=1 if ref_mo=="01" | ref_mo=="02" | ref_mo=="03"
    297. replace previous=0 if previous==.
    298.
    . sort newid
    299. bysort newid: egen var_`i'_cur=sum(cost*current)
    300. bysort newid: egen var_`i'_pre=sum(cost*previous)
    301.
    . drop if newid==newid[_n-1]
    302. keep newid var_`i'_cur var_`i'_pre
    303.
    . save us_`i'_2009q2, replace
    304.
    . }
    305.
    . else {
    306.
    . keep newid
    307. sort newid
    308. drop if newid==newid[_n-1]
    309. gen var_`i'_cur=.
    310. gen var_`i'_pre=.
    311.
    . save us_`i'_2009q2, replace
    312.
    . }
    313.
    .
    .
    . use ${datapath}\mtbi093, replace
    314.
    . gen tem=1 if ucc=="`i'"
    315. replace tem=0 if tem==.
    316. egen tem_max=max(tem)
    317. if tem_max>0 {
    318.
    . keep if ucc=="`i'"
    319.
    . gen current=1 if ref_mo=="07" | ref_mo=="08" | ref_mo=="09"
    320. replace current=0 if current==.
    321.
    . gen previous=1 if ref_mo=="04" | ref_mo=="05" | ref_mo=="06"
    322. replace previous=0 if previous==.
    323.
    . sort newid
    324. bysort newid: egen var_`i'_cur=sum(cost*current)
    325. bysort newid: egen var_`i'_pre=sum(cost*previous)
    326.
    . drop if newid==newid[_n-1]
    327. keep newid var_`i'_cur var_`i'_pre
    328.
    . save us_`i'_2009q3, replace
    329.
    . }
    330.
    . else {
    331.
    . keep newid
    332. sort newid
    333. drop if newid==newid[_n-1]
    334. gen var_`i'_cur=.
    335. gen var_`i'_pre=.
    336.
    . save us_`i'_2009q3, replace
    337.
    . }
    338.
    .
    .
    . use ${datapath}\mtbi094, replace
    339.
    . gen tem=1 if ucc=="`i'"
    340. replace tem=0 if tem==.
    341. egen tem_max=max(tem)
    342. if tem_max>0 {
    343.
    . keep if ucc=="`i'"
    344.
    . gen current=1 if ref_mo=="10" | ref_mo=="11" | ref_mo=="12"
    345. replace current=0 if current==.
    346.
    . gen previous=1 if ref_mo=="07" | ref_mo=="08" | ref_mo=="09"
    347. replace previous=0 if previous==.
    348.
    . sort newid
    349. bysort newid: egen var_`i'_cur=sum(cost*current)
    350. bysort newid: egen var_`i'_pre=sum(cost*previous)
    351.
    . drop if newid==newid[_n-1]
    352. keep newid var_`i'_cur var_`i'_pre
    353.
    . save us_`i'_2009q4, replace
    354.
    . }
    355.
    . else {
    356.
    . keep newid
    357. sort newid
    358. drop if newid==newid[_n-1]
    359. gen var_`i'_cur=.
    360. gen var_`i'_pre=.
    361.
    . save us_`i'_2009q4, replace
    362.
    . }
    363.
    .
    .
    . use ${datapath}\mtbi101, replace
    364.
    . gen tem=1 if ucc=="`i'"
    365. replace tem=0 if tem==.
    366. egen tem_max=max(tem)
    367. if tem_max>0 {
    368.
    . keep if ucc=="`i'"
    369.
    . gen previous=1 if ref_mo=="10" | ref_mo=="11" | ref_mo=="12"
    370. replace previous=0 if previous==.
    371.
    . sort newid
    372. bysort newid: egen var_`i'_pre=sum(cost*previous)
    373.
    . drop if newid==newid[_n-1]
    374. keep newid var_`i'_pre
    375.
    . save us_`i'_2010q1, replace
    376.
    . }
    377.
    . else {
    378.
    . keep newid
    379. sort newid
    380. drop if newid==newid[_n-1]
    381. gen var_`i'_pre=.
    382.
    . save us_`i'_2010q1, replace
    383.
    . }
    384.
    .
    .
    . ************************************************** ******************************
    .
    .
    .
    . forvalues j=10/18 {
    385.
    . local x=`j'+1
    386.
    . use ${datapath}\mtbi`j'1x, replace
    387.
    . gen tem=1 if ucc=="`i'"
    388. replace tem=0 if tem==.
    389. egen tem_max=max(tem)
    390. if tem_max>0 {
    391.
    . keep if ucc=="`i'"
    392.
    . gen current=1 if ref_mo=="01" | ref_mo=="02" | ref_mo=="03"
    393. replace current=0 if current==.
    394.
    . sort newid
    395. bysort newid: egen var_`i'_cur=sum(cost*current)
    396.
    . drop if newid==newid[_n-1]
    397. keep newid var_`i'_cur
    398.
    . save us_`i'_20`j'q1x, replace
    399.
    . }
    400.
    . else {
    401.
    . keep newid
    402. sort newid
    403. drop if newid==newid[_n-1]
    404. gen var_`i'_cur=.
    405.
    . save us_`i'_20`j'q1x, replace
    406.
    . }
    407.
    .
    .
    . use ${datapath}\mtbi`j'2, replace
    408.
    . gen tem=1 if ucc=="`i'"
    409. replace tem=0 if tem==.
    410. egen tem_max=max(tem)
    411. if tem_max>0 {
    412.
    . keep if ucc=="`i'"
    413.
    . gen current=1 if ref_mo=="04" | ref_mo=="05" | ref_mo=="06"
    414. replace current=0 if current==.
    415.
    . gen previous=1 if ref_mo=="01" | ref_mo=="02" | ref_mo=="03"
    416. replace previous=0 if previous==.
    417.
    . sort newid
    418. bysort newid: egen var_`i'_cur=sum(cost*current)
    419. bysort newid: egen var_`i'_pre=sum(cost*previous)
    420.
    . drop if newid==newid[_n-1]
    421. keep newid var_`i'_cur var_`i'_pre
    422.
    . save us_`i'_20`j'q2, replace
    423.
    . }
    424.
    . else {
    425.
    . keep newid
    426. sort newid
    427. drop if newid==newid[_n-1]
    428. gen var_`i'_cur=.
    429. gen var_`i'_pre=.
    430.
    . save us_`i'_20`j'q2, replace
    431.
    . }
    432.
    .
    .
    . use ${datapath}\mtbi`j'3, replace
    433.
    . gen tem=1 if ucc=="`i'"
    434. replace tem=0 if tem==.
    435. egen tem_max=max(tem)
    436. if tem_max>0 {
    437.
    . keep if ucc=="`i'"
    438.
    . gen current=1 if ref_mo=="07" | ref_mo=="08" | ref_mo=="09"
    439. replace current=0 if current==.
    440.
    . gen previous=1 if ref_mo=="04" | ref_mo=="05" | ref_mo=="06"
    441. replace previous=0 if previous==.
    442.
    . sort newid
    443. bysort newid: egen var_`i'_cur=sum(cost*current)
    444. bysort newid: egen var_`i'_pre=sum(cost*previous)
    445.
    . drop if newid==newid[_n-1]
    446. keep newid var_`i'_cur var_`i'_pre
    447.
    . save us_`i'_20`j'q3, replace
    448.
    . }
    449.
    . else {
    450.
    . keep newid
    451. sort newid
    452. drop if newid==newid[_n-1]
    453. gen var_`i'_cur=.
    454. gen var_`i'_pre=.
    455.
    . save us_`i'_20`j'q3, replace
    456.
    . }
    457.
    .
    .
    . use ${datapath}\mtbi`j'4, replace
    458.
    . gen tem=1 if ucc=="`i'"
    459. replace tem=0 if tem==.
    460. egen tem_max=max(tem)
    461. if tem_max>0 {
    462.
    . keep if ucc=="`i'"
    463.
    . gen current=1 if ref_mo=="10" | ref_mo=="11" | ref_mo=="12"
    464. replace current=0 if current==.
    465.
    . gen previous=1 if ref_mo=="07" | ref_mo=="08" | ref_mo=="09"
    466. replace previous=0 if previous==.
    467.
    . sort newid
    468. bysort newid: egen var_`i'_cur=sum(cost*current)
    469. bysort newid: egen var_`i'_pre=sum(cost*previous)
    470.
    . drop if newid==newid[_n-1]
    471. keep newid var_`i'_cur var_`i'_pre
    472.
    . save us_`i'_20`j'q4, replace
    473.
    . }
    474.
    . else {
    475.
    . keep newid
    476. sort newid
    477. drop if newid==newid[_n-1]
    478. gen var_`i'_cur=.
    479. gen var_`i'_pre=.
    480.
    . save us_`i'_20`j'q4, replace
    481.
    . }
    482.
    .
    .
    . use ${datapath}\mtbi`x'1, replace
    483.
    . gen tem=1 if ucc=="`i'"
    484. replace tem=0 if tem==.
    485. egen tem_max=max(tem)
    486. if tem_max>0 {
    487.
    . keep if ucc=="`i'"
    488.
    . gen previous=1 if ref_mo=="10" | ref_mo=="11" | ref_mo=="12"
    489. replace previous=0 if previous==.
    490.
    . sort newid
    491. bysort newid: egen var_`i'_pre=sum(cost*previous)
    492.
    . drop if newid==newid[_n-1]
    493. keep newid var_`i'_pre
    494.
    . save us_`i'_20`x'q1, replace
    495.
    . }
    496.
    . else {
    497.
    . keep newid
    498. sort newid
    499. drop if newid==newid[_n-1]
    500. gen var_`i'_pre=.
    501.
    . save us_`i'_20`x'q1, replace
    502.
    . }
    503.
    .
    .
    . }
    504.
    .
    .
    . }
    file \mtbi061x.dta not found
    r(601);

  • #2
    Here is the github repo for the source code: https://github.com/S-Park1228/Analyz...tion-Microdata
    Here is the data source: https://www.bls.gov/cex/pumd_data.htm#stata

    Comment


    • #3
      data_path has an underscore, which is omitted from the -use- statement invoking it. Hence ${datapath} is empty and Stata attempts to load a file from the root directory.

      -set trace on- is a good way to find problems like this, however if a error relates to any statement involving a macro variable, it is often easiest to just display the variable at that point. It may not be what you think.
      Last edited by Daniel Feenberg; 29 Feb 2024, 05:54.

      Comment

      Working...
      X