Announcement

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

  • Meaning of different code

    1. Create the dummies and estimate
    levelsof year, local(time)
    foreach t of local time {
    local y_rr = `t' - 1975
    gen intra_nafta`t' = yr`y_rr' * intra_nafta
    gen imp_nafta_rest`t' = yr`y_rr' * imp_nafta_rest
    }

    xtreg lnV lncGDP lnpGDP lnD yr* intra_nafta* imp_nafta_rest*, fe vce(robust)

    Who can help me explain how y_rr is defined in the above code? What meaning of yr`y_rr' * intra_nafta ? Thank you!

  • #2
    The question omits the context, namely the data structure you're using. The code implies that your data include variables like

    Code:
    yr5  yr10 yr15
    for something or other in years 1980 1985 1990 and so on. That is, data for 1980 are stored in a variable yr5 (5 = 1980 - 1975), and so on. You may have many more years. At the same time, it seems odd that there is evidently a variable year too, so I can't follow whether your layout is long or wide.

    The code is calculating interaction terms in a loop before calling up xtreg

    On the other hand, if you're reading someone else's code somewhere, they should describe their data structure -- if they did a good job.

    There are many introductions to loops and local macros in Stata. One familiar to me is https://journals.sagepub.com/doi/pdf...36867X20976340 (note the correction at https://journals.sagepub.com/doi/pdf...6867X211025839)

    Comment


    • #3
      My time period is 1985-2004. I'm still a little confused about y_rr = `t' - 1975, and can we write in other forms,for example, y_rr = `t' - 1970 or other forms? ( This paper want to study the impact of Free Trade Zone on trade)
      Originally posted by Nick Cox View Post
      The question omits the context, namely the data structure you're using. The code implies that your data include variables like

      Code:
      yr5 yr10 yr15
      for something or other in years 1980 1985 1990 and so on. That is, data for 1980 are stored in a variable yr5 (5 = 1980 - 1975), and so on. You may have many more years. At the same time, it seems odd that there is evidently a variable year too, so I can't follow whether your layout is long or wide.

      The code is calculating interaction terms in a loop before calling up xtreg

      On the other hand, if you're reading someone else's code somewhere, they should describe their data structure -- if they did a good job.

      There are many introductions to loops and local macros in Stata. One familiar to me is https://journals.sagepub.com/doi/pdf...36867X20976340 (note the correction at https://journals.sagepub.com/doi/pdf...6867X211025839)

      Comment


      • #4
        To get another answer, please tell us what variables you have by showing the results of

        Code:
        ds yr* 

        Comment


        • #5

          label var ccode "Country code"
          label var pcode "Partner code"
          label var year "Year"
          label var exp_tv "value of exported goods"
          label var exp_q "physical aount of exported goods ( in kg)"
          label var exp_uv "average Unit value of exported goods"
          label var imp_tv "value of imported goods"
          label var imp_q "physical aount of imported goods ( in kg)"
          label var imp_uv "average Unit value of imported goods"
          label var km "bilateral distance"
          label var name "country name"
          label var lang1 "first official language"
          label var lang2 "second official language"
          label var cgdp_c2000 "home's real GDP, year base = 2000"
          label var cgdp_current "home's current GDP"
          label var cgdp_pcppp_c2000 "home's real GDP per capita in PPP, year base = 2000"
          label var cgdp_pcppp_current "home's current GDP per capita in PPP"


          label var com_lang "1 if common language"
          label var border "1 if common border"
          label var ldlock "1 if landlocked"
          label var island "1 if island"label var exp_tv "value of exported goods"

          gen nafta = (ccode=="CAN" | ccode=="MEX" | ccode=="USA")
          label var nafta "1 if home is nafta member"
          gen pnafta = (pcode=="CAN" | pcode=="MEX" | pcode=="USA")
          label var pnafta "1 if partner is nafta member"
          gen intra_nafta = (ccode=="CAN" | ccode=="MEX" | ccode=="USA") & (pcode=="CAN" | pcode=="MEX" | pcode=="USA")
          replace intra_nafta = 0 if year < 1994
          label var intra_nafta "1 if trade bewteen nafta members"
          gen imp_nafta_rest = (ccode=="CAN" | ccode=="MEX" | ccode=="USA") & (pcode!="CAN" & pcode!="MEX" & pcode!="USA")
          replace imp_nafta_rest = 0 if year < 1994
          label var imp_nafta_rest "1 if nafta's imports from the rest of the world"


          These are the related variables.
          Last edited by Kendal zhang; 02 May 2022, 22:03.

          Comment


          • #6
            Sorry, but #5 does not answer #4.

            Code:
            ds yr*
            is a Stata command. If the code in #1 applies to your data then its results should include variables whose names begin with yr.

            Detail: It is just possible that the references are to scalars. in which case

            Code:
            scalar list
            should list them.

            Comment


            • #7
              ccode imp_tv cgdp_c2000 pgdp_pc~2000 island
              pcode imp_q cgdp_current pgdp_pcppp~t nafta
              year imp_uv cgdp_pc~2000 km pnafta
              name exp_tv cgdp_pcppp~t com_lang intra_nafta
              lang1 exp_q pgdp_c2000 border imp_nafta_~t
              lang2 exp_uv pgdp_current ldlock

              Here are the variables.

              Comment


              • #8
                Thanks for #7. My only guess now, as in #2.is that the code in #1 is someone else's code referring to a different data structure.

                Comment


                • #9
                  OK, thank you very much!

                  Comment

                  Working...
                  X