首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Stata:找出哪种动物越过边界进入德国

Stata:找出哪种动物越过边界进入德国
EN

Stack Overflow用户
提问于 2017-01-29 06:22:44
回答 1查看 37关注 0票数 0

我想找出在过去的10年里,哪种动物越境进入德国最多。我的表结构如下:

代码语言:javascript
运行
复制
+------+----------+-------------+
| Year |  Animal  | Coming from |
+------+----------+-------------+
| 2000 | bear     | netherlands |
| 2001 | ant      | netherlands |
| 2001 | spider   | netherlands |
| 2002 | dog      | poland      |
| 2003 | dinosaur | swiss       |
| 2004 | ant      | austria     |
| 2005 | bear     | poland      |
| 2006 | ant      | austria     |
| 2007 | spider   | belgium     |
| 2007 | cat      | luxembourg  |
| 2008 | fish     | belgium     |
| 2008 | ant      | poland      |
| 2009 | dog      | poland      |
| 2010 | dog      | netherlands |
+------+----------+-------------+

这只是示例数据:我的实际表要大得多,有超过7k个条目。

我想知道的是:

这种动物每年至少来德国一次。在这里我有困难来解释它。我的意思是,如果一只熊每年来德国,不管他来自哪个国家,11年来(至少一次)。所以熊得到了11。现在我想对不同的动物进行分组,所以我得到了一个由两列组成的表格,它告诉我每年哪种动物来到德国,可能只有11年中的5年。等等。

我如何在Stata中实现这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-29 07:12:26

请安装dataex,以便更好地为Stata问题提供数据示例:

代码语言:javascript
运行
复制
ssc inst dataex 

this paper中讨论了计算不同值的原理。

这可能会有所帮助:

代码语言:javascript
运行
复制
clear 
input Year   str8 Animal   str11 Coming_from 
2000  bear      netherlands 
2001  ant       netherlands 
2001  spider    netherlands 
2002  dog       poland      
2003  dinosaur  swiss       
2004  ant       austria     
2005  bear      poland      
2006  ant       austria     
2007  spider    belgium     
2007  cat       luxembourg  
2008  fish      belgium     
2008  ant       poland      
2009  dog       poland      
2010  dog       netherlands 
end 

egen tag = tag(Coming_from Animal Year)
egen distinct = total(tag), by(Coming_from Year)
tabdisp Coming_from Year, c(distinct) 

------------------------------------------------------------------------------
            |                               Year                              
Coming_from | 2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010
------------+-----------------------------------------------------------------
    austria |                            1           1                        
    belgium |                                              1     1            
 luxembourg |                                              1                  
netherlands |    1     2                                                     1
     poland |                1                 1                 1     1      
      swiss |                      1                                          
------------------------------------------------------------------------------

egen ndistinct = total(tag), by(Coming_from Animal) 

tabdisp Coming_from Animal, c(ndistinct) 

----------------------------------------------------------------------------
            |                             Animal                            
Coming_from |      ant     bear      cat dinosaur      dog     fish   spider
------------+---------------------------------------------------------------
    austria |        2                                                      
    belgium |                                                     1        1
 luxembourg |                          1                                    
netherlands |        1        1                          1                 1
     poland |        1        1                          2                  
      swiss |                                   1                           
----------------------------------------------------------------------------
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41915495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档