{"action":"created","issue":{"url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2659","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2659/labels{/name}","comments_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2659/comments","events_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2659/events","html_url":"https://github.com/statsmodels/statsmodels/issues/2659","id":111900826,"number":2659,"title":"add_constant considers a column of all 0s as a constant.","user":{"login":"bjlange","id":780375,"avatar_url":"https://avatars.githubusercontent.com/u/780375?v=3","gravatar_id":"","url":"https://api.github.com/users/bjlange","html_url":"https://github.com/bjlange","followers_url":"https://api.github.com/users/bjlange/followers","following_url":"https://api.github.com/users/bjlange/following{/other_user}","gists_url":"https://api.github.com/users/bjlange/gists{/gist_id}","starred_url":"https://api.github.com/users/bjlange/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjlange/subscriptions","organizations_url":"https://api.github.com/users/bjlange/orgs","repos_url":"https://api.github.com/users/bjlange/repos","events_url":"https://api.github.com/users/bjlange/events{/privacy}","received_events_url":"https://api.github.com/users/bjlange/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/comp-base","name":"comp-base","color":"ededed"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/comp-tools","name":"comp-tools","color":"DDDDDD"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/design","name":"design","color":"99ffcc"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/type-bug","name":"type-bug","color":"ff9999"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/type-enh","name":"type-enh","color":"99ffff"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/statsmodels/statsmodels/milestones/9","html_url":"https://github.com/statsmodels/statsmodels/milestones/0.8","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/milestones/9/labels","id":930392,"number":9,"title":"0.8","description":"","creator":{"login":"josef-pkt","id":440735,"avatar_url":"https://avatars.githubusercontent.com/u/440735?v=3","gravatar_id":"","url":"https://api.github.com/users/josef-pkt","html_url":"https://github.com/josef-pkt","followers_url":"https://api.github.com/users/josef-pkt/followers","following_url":"https://api.github.com/users/josef-pkt/following{/other_user}","gists_url":"https://api.github.com/users/josef-pkt/gists{/gist_id}","starred_url":"https://api.github.com/users/josef-pkt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josef-pkt/subscriptions","organizations_url":"https://api.github.com/users/josef-pkt/orgs","repos_url":"https://api.github.com/users/josef-pkt/repos","events_url":"https://api.github.com/users/josef-pkt/events{/privacy}","received_events_url":"https://api.github.com/users/josef-pkt/received_events","type":"User","site_admin":false},"open_issues":223,"closed_issues":12,"state":"open","created_at":"2015-01-11T13:17:39Z","updated_at":"2015-10-16T20:22:16Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-10-16T20:01:34Z","updated_at":"2015-10-20T00:10:22Z","closed_at":null,"body":"`tools.add_constant` uses the variance of columns to detect if a constant is already present. Unfortunately this means that if a column of all 0s is provided, it considers it a constant even thought the model can't use this pre-existing column.\r\n\r\nExample:\r\n```python\r\nimport statsmodels as sm\r\nimport pandas as pd\r\n\r\nX = pd.DataFrame([[0, 1, 3.0],\r\n                  [0, 0, 2.2],\r\n                  [0, 1, 4.5]])\r\n\r\n# print X \r\n#    0  1    2\r\n# 0  0  1  3.0\r\n# 1  0  0  2.2\r\n# 2  0  1  4.5\r\n\r\nX_const = sm.tools.add_constant(X)\r\n\r\n# print X_const\r\n#    0  1    2\r\n# 0  0  1  3.0\r\n# 1  0  0  2.2\r\n# 2  0  1  4.5\r\n```\r\n\r\nSeems to me that `add_constant` should either check the content of the columns considered to be constant, or at the least a warning or exception should be raised at some point if one of the columns is all zeros.\r\n\r\nI'm happy to open a pull request to change this, just thought I'd open an issue first here to discuss how it should work before writing any code."},"comment":{"url":"https://api.github.com/repos/statsmodels/statsmodels/issues/comments/149381982","html_url":"https://github.com/statsmodels/statsmodels/issues/2659#issuecomment-149381982","issue_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2659","id":149381982,"user":{"login":"bjlange","id":780375,"avatar_url":"https://avatars.githubusercontent.com/u/780375?v=3","gravatar_id":"","url":"https://api.github.com/users/bjlange","html_url":"https://github.com/bjlange","followers_url":"https://api.github.com/users/bjlange/followers","following_url":"https://api.github.com/users/bjlange/following{/other_user}","gists_url":"https://api.github.com/users/bjlange/gists{/gist_id}","starred_url":"https://api.github.com/users/bjlange/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjlange/subscriptions","organizations_url":"https://api.github.com/users/bjlange/orgs","repos_url":"https://api.github.com/users/bjlange/repos","events_url":"https://api.github.com/users/bjlange/events{/privacy}","received_events_url":"https://api.github.com/users/bjlange/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T00:10:21Z","updated_at":"2015-10-20T00:10:21Z","body":"Makes sense, I'll just leave that part alone."}}