Announcement

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

  • Gravity model , Fot( frequency of trade)

    Dear all!

    Hello! here is Sujin,

    Im covering trade panel data between 100 import, export countries.

    I have trade data which is 1 if trade value>0 , 0 if trade value= 0

    I hope to get accumulated frequency data for each country combination


    For example, US, Canada had a data (if they only had trade 2000,2001)

    import, export, year, trade(0 or 1) ,accumulated frequency
    US, Cananda,2000, 1, 1
    US,Canada, 2001, 1, 2
    US, Canada, 2002, 0, 2


    I hope to make accumulated frequency
    but I do not know command!!

    If any of you know about it,

    If you share information
    It would be really grateful and appreciated

    Thank you
    Sujin
    Last edited by KIM SUJIN; 17 Jul 2018, 19:13.

  • #2
    Look at the egen command with the by prefix.

    All the best,

    Joao

    Comment


    • #3
      Thank you
      Prof.Joao Santos Silva!



      My data variables are
      import country, export country, value, year period,

      I used command

      collapse (sum) Value_, by(YearPeriod country )
      sort country Year

      bysort(country): egen example=sum(Value_)

      but I got 'invalid syntax' sign.

      And I wonder which part is wrong


      Thank you so much!

      Comment


      • #4
        Sorry, I am not familiar with those commands; hopefully someone else will help.

        Best wishes,

        Joao

        Comment


        • #5
          Thank you so much!!

          Comment


          • #6
            This works, but only if there are no duplicate observations for each combination of import, export and year.
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str6(export import) float(year trade)
            "US" "Canada" 2000 1
            "US" "Canada" 2001 1
            "US" "Canada" 2002 0
            end
            
            bys export import (year): gen acfreq = trade if _n==1
            bys export import (year): replace acfreq = trade + acfreq[_n-1] if _n!=1
            Also, for future posts, please use dataex to provide a data example. This makes it tons easier for people to answer your question. See more on why and how in the FAQ: https://www.statalist.org/forums/help#stata

            Comment


            • #7
              It works!! Thank you so much!!

              Comment

              Working...
              X