Announcement

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

  • How can I creat variables from those four euqations?

    Hello everyone!!!!
    I would like to create five variables from following equations. The export from i=173 and j=173. TF= Trade flow and FTA= free trade agreement. I am not sure my code are correct or not for those four equations.


    gen LOGTF= ln(TFij/GDPi*GDPj)
    gen BVDIST= lnDist- (1/173)*sum(lnDist)-(1/173)*sum(lnDist)+(1/173*173)*sum(lnDist)*sum(lnDist)
    gen BVADJ= ADJij- (1/173)*sum(ADJij)-(1/173)*sum(ADJij)+(1/173*173)*sum(ADJij)*sum(ADJij)
    gen BVLANGij= LANGij- (1/173)*sum(LANGij)-(1/173)*sum(LANGij)+(1/173*173)*sum(LANGij)*sum(LANGij)
    gen BVFTAij= FTAij- (1/173)*sum(FTAij)-(1/173)*sum(FTAij)+(1/173*173)*sum(FTAij)*sum(FTAij)



    Attached Files
    Last edited by Myo Win; 30 Jun 2018, 18:34.

  • #2
    You'll increase your chances of a helpful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    You code is far off. egen with sum does running sums - you need egen with total. Your ratios only work (if they do work) if the proportions are constant over the items being summed.

    First, use egen with the total by whatever the sums are over to generate your sums. Then you put those sums together into the larger equations. For the sum of sums, you'll need to do egen twice.



    Comment


    • #3
      Thank you for your suggestion @ Phil Bromiley. I will try it...

      Code:
      bysort iso3j: egen sumDist=total( lnDist)
      rename sumDist sumDistj
      bysort iso3i: egen sumDisti=total( lnDist)
      bysort iso3i: egen sumDistij=total( sumDistj )
      label variable sumDistj "bysort iso3j: egen sumDistj=total( lnDist)"
      label variable sumDisti "bysort iso3i: egen sumDisti=total( lnDist)"
      label variable sumDistij "bysort iso3i: egen sumDistij=total( sumDistj )"
      su sumDistij
      gen AA=(1/173)*sumDistj
      label variable AA "=(1/173)*sumDistj"
      sort iso3j
      gen BB=(1/173)*sumDisti
      label variable BB "=(1/173)*sumDisti"
      gen CC=sumDistij/(173*173)
      label variable CC "=sumDistij/(173*173)"
      gen BVDISTij= lnDist- AA- BB+ CC

      Comment

      Working...
      X