Announcement

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

  • Statistics by sub_group

    I need to produce statistics on :
    ** The number of patents, green patents, proportion green, per year (total at the end).

    NUMBER OF PATENTS I managed this.
    bysort filing_year: asdoc tabstat patent_num, stat(N min max p10 p25 p50 p75 p99)

    NUMBER of GREEN PATENTS
    I have created a dummy variable (0-9) called "scheme_code" which classify the patents into not green (=0) and green(1-9).
    How can I tell STATA to produce statistics for green patents (scheme_code between 1 and 9) per year?

    PROPORTION GREEN PER YEAR
    How can I produce a proportion of green patents per year statistics?

    Thanks

  • #2
    Giulia:
    if your query does not match with https://www.statalist.org/forums/help#adviceextras #4, please share what you typed and waht Stata gave you back, along with and extcerpt/example of your dataset (as per FAQ again). Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3

      Code:
      egen not_green = total(green == 0), by(year)
      egen green = total(inrange(green, 1, 9)), by(year)
      tabdisp year, c(green not_green)
      I wouldn't call a variable with 10 distinct values a dummy variable. It's categorical, perhaps ordinal.

      Comment


      • #4
        Thanks Carlo for your answer.

        Here my varibles:
        - Firm: permno
        - year: filing_year
        - patents: patent_num
        - patent classification btw green and no green is a dummy variable: green_d which takes velues btw 1 and 9 if is green and 0 otherwise

        Summary stats:

        Variable Obs Mean Std. Dev. Min Max

        permno 3,160,451 40501.84 28722.36 10001 93436
        filing_year 3,160,451 1993.946 22.30416 1834 2022
        patent_num 3,160,451 6693380 2634605 1570604 1.15e+07
        scheme_code 3,160,451 .2368975 1.172737 0 9
        green_d 3,160,451 .0434232 .2038079 0 1


        //Number of patents per year here is my code
        bysort filing_year: asdoc tabstat patent_num, stat(N min max p10 p25 p50 p75 p99)

        //Number of green patents per year
        based on my scheme_code I can see that, overall I have:
        - 3,023,214 No Green patents
        - 137237 Greent patents which are classes (1-9)

        What I would like is to determine how many green patents I have per year. I have run the below code which does not return the outcome that I want as it includes also the No-green patents.
        egen n_green = total(green_d), by(permno filing_year)
        bysort filing_year: asdoc tabstat n_green, stat(N min max p10 p25 p50 p75 p99)


        Hope you can help me.
        Thanks

        Comment


        • #5
          Thanks a lot Nick. It worked.
          Apologies for the wrong terminology used.

          Comment


          • #6
            I had to determine the number of patents number of firms, citations , avrage Xi_nominal,average Xi_real per year (total at the end)

            Here what I have done in the do file:

            egen n_patents = total(inrange(scheme_code, 0, 9)), by(permno filing_year) // I computed how many patents per company I have per year

            egen n_cites = total(cites), by (permno filing_year) // I computed how many citation per company I have per year

            bys permno filing_year: egen avg_xi_nominal = mean(xi_nominal) // I have computed the avergae per company per year of xi_nominal

            bys permno filing_year: egen avg_xi_real = mean(xi_real) // I have computed the avergae per company per year of xi_nominal

            sort permno filing_year

            order patent_num permno filing_year n_patents cites n_cites xi_nominal avg_xi_nominal xi_real avg_xi_real

            bysort filing_year: asdoc tabstat n_patents n_cites avg_xi_nominal avg_xi_real, stat(N)

            Here is where I try to produce the table but the outcome is not correct.
            I would like a table that shows the n_patents, citations (n_cites), avrage Xi_nominal, average Xi_real per year per firm.

            Can I kindly ask your help to understand what I do wrong?
            Thanks


            Comment


            • #7
              On the face of it, your problem is with asdoc from SSC, which I leave open to people who use it.

              Comment


              • #8
                How can I produce the same outcome without asdoc, please?

                Comment


                • #9
                  Still open to others as far as I am concerned. I don't use asdoc and am not familiar with what it does, so working out how to replicate it is not something I can undertake.

                  Comment


                  • #10
                    Here is the amended code without asdoc.

                    ** The number of patents number of firms, citations , avrage Xi_nominal,average Xi_real per year (total at the end)

                    bys permno filing_year: egen n_patents_firm = count(n_patents)// I computed how many patents per company I have per year
                    bys permno filing_year: egen n_citations = sum(cites) // I computed how many citation per company I have per year
                    bys permno filing_year: egen avg_xi_nominal = mean(xi_nominal) // I have computed the avergae per company per year of xi_nominal
                    bys permno filing_year: egen avg_xi_real = mean(xi_real) // I have computed the avergae per company per year of xi_nominal

                    sort permno filing_year

                    order patent_num permno filing_year n_patents_firm cites n_citations xi_nominal avg_xi_nominal xi_real avg_xi_real cpc scheme_code cites filing_date issue_date issue_year

                    tabdisp filing_year, c(n_patents_firm n_citations avg_xi_nominal avg_xi_real)

                    This is a snapshot of what I get as outcome:



                    filing_ye
                    ar n_patents_firm n_citations avg_xi_nominal avg_xi_real

                    1834 1 7 .2017942 1.151761
                    1835 3 1 .193488 1.174547
                    1836 1 3 .0463756 .3455161
                    1837 1 4 .3967184 2.652035
                    1838 1 0 .2393945 1.358425
                    1868 1 1 2.22735 6.967609
                    1883 1 6 .3180774 1.794472
                    1887 1 1 .1859463 1.055137
                    1903 1 1 .4522994 1.388189
                    1904 1 0 .2148499 1.184709
                    1907 1 0 .6957758 3.836594
                    1910 1 0 .5150331 2.905621
                    1913 1 0 .4253995 2.578819
                    1914 1 1 .1686057 .9512091
                    1915 1 0 .0090889 .0518758
                    1916 4 21 .77889 4.557581
                    1917 2 6 .0846542 .5110795
                    1918 1 1 .0090889 .0518758
                    1919 2 8 .2244583 1.268149
                    1920 1 2 .098946 .5456004

                    Comment

                    Working...
                    X