Announcement

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

  • Regression with fixed and random effects

    Hello everybody,

    I would like to reproduce the table below (just the "All cities" column). It come from an article but I have some trouble to figure out what code I should write because of the fixed effects and the random effect as explained below the table. If someone could help me figure it out, I would be very thankful.


    You can find the database on this link, in the "Additional Data" section
    http://www.cgeh.nl/urbanisation-hub-...izes-1500-2000

    The database is not completed, so it is required to add some variables.
    /*Christian Holy Cities*/
    gen christian_holy_city=0
    replace christian_holy_city=1 if indicator ==337 /*Roma*/
    replace christian_holy_city=1 if indicator ==613 /*Jerusalem*/
    replace christian_holy_city=1 if indicator ==598 /*Constantinople*/
    replace christian_holy_city=1 if indicator ==500 /*Compostelle*/

    /*Gen ln*/
    gen lnUPm = ln(musfup)
    gen lnUPc = ln(chrfup)
    gen lnPOP10 = ln(citypop_le10)
    gen lnrome = ln( drome)
    gen lnmecca = ln(dmecca)
    gen lnbyzantium= ln( dbyzantium)
    gen lnelevation=ln( elevation_m)
    gen lnrugg10 = ln( rugg10)

    Thank you very much for your time and your help !

    Maxim Dechamps
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	176.1 KB
ID:	1450055

  • #2
    You didn't get a quick answer. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. Actual copies of what happened will be better than your description. And we prefer you don't post pictures. If it is worth our taking time to help you, it is worth you writing out your problem.

    You can run these with xtreg,re for random effects. If you need to also have fixed effects, you can add these with i.panel (e.g., i.country and i.century). The table can be made with any of a variety of output programs including estout and outreg2. Stata has putdocx also, but it looks more complex than the user-written routines.

    Comment


    • #3
      Hello everybody,

      Thank you Phil Bromiley for your help, it was already relevant to solve my problem.
      I'm sorry I didn't get the chance to follow the FAQ on my first message. I read it since then and normally, I'll respect it from now on.

      First of all, let me rephrase my problem : I would like to repoduce a table that I have seen in an article. The article in question is "From Baghdad to London : Unravelling Urban Development in Europe, The Middle East and North Africa, 800-1800" written by Bosker, Buringh and van Zanden in 2013 (https://www.mitpressjournals.org/doi...2/REST_a_00284). The table is the one on page 1426.

      I'm sorry not being able to share the database using dataex, but I'm working on a computer belonging to my university. Therefore I can't add packages. But the database can be found on this link, in the "Additionnal Data" section : http://www.cgeh.nl/urbanisation-hub-...izes-1500-2000.

      I have already done simple regressions but this one seems more complex. We have the dependant variable (ln - natural logarithm - of the population) and multiple independants variables (sea, river, roman road, hub roman road, caravan, caravan hub, bishop, archbishop, christian holy city, muslim holy city, capital, university, madrasa, plundered and two others variables created by the authors).

      Besides that, we have some control variables (a muslim dummy, ln of the distance to some cities (Roma, Mecca and Byzantum), ln of the elevation above the sea, ln of the ruggedness of the surrounding area and the cultivation potential). I treated those control variables as independant variables as explained here : https://www.statalist.org/forums/for...ntrol-variable.

      There is also econzone-, country- and century-fixed effects and a city-specific random effects.

      So using Phil Bromiley's help, I already regress using xtreg:

      Code:
      /*Christian Holy Cities*/
      gen christian_holy_city=0
      replace christian_holy_city=1 if indicator ==337 /*Roma*/
      replace christian_holy_city=1 if indicator ==613 /*Jerusalem*/
      replace christian_holy_city=1 if indicator ==598 /*Constantinople*/
      replace christian_holy_city=1 if indicator ==500 /*Compostelle*/
      
      /*Gen ln*/
      gen lnUPm = ln(musfup)
      gen lnUPc = ln(chrfup)
      gen lnPOP10 = ln(citypop_le10)
      gen lnrome = ln( drome)
      gen lnmecca = ln(dmecca)
      gen lnbyzantium= ln( dbyzantium)
      gen lnelevation=ln( elevation_m)
      gen lnrugg10 = ln( rugg10)
      
      /* */
      xtset indicator year
      
      /*country:  string variables may not be used as factor variables*/
      encode country, gen(country1)
      
      /*Regression*/
      xtreg lnPOP10 sea river rom_road_nohub hub_3rr caravan_nohub caravan_hub bishop archbishop christian_holy_city muslim_holy_city capital university madrassa01 plundered lnUPm lnUPc i.ecozones i.country1 i.year muslim lnrome lnmecca lnbyzantium lnelevation lnrugg10 soilquality , re
      The first two steps are there to finalize the database while the others are the preparation of the regression and the regression itself.
      Here is what I obtained (Sorry for posting a screenshot but, again, it looks like I can't add packages) :

      Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	40.7 KB
ID:	1450479


      After that, I also have a coefficient for each ecozone, country and century and the control variables.
      As we can see the coefficient obtained here and in the article are quite similair without being exactly the same. We can draw the same conclusion for the R2 and for the number of observations.

      Therefore, I would like to know if my code is correct ? Or if I should/could change something that would give me closer results ?
      Also, if everything is correct, how could the difference be explained ? Does the random effect matter ?

      Thank your for your time and your help,

      Maxim Dechamps

      Comment

      Working...
      X