当变量1
高于pax
且100
之上时,如何在Stata中创建一个虚拟变量并采用0
的值?
缺少的值应标记为0
。
我的代码如下:
generate type = 0
replace type = 1 if pax > 100
问题在于,Stata将所有缺失值标记为1
,而不是将其保留为0
。
当变量1
高于pax
且100
之上时,如何在Stata中创建一个虚拟变量并采用0
的值?
缺少的值应标记为0
。
我的代码如下:
generate type = 0
replace type = 1 if pax > 100
问题在于,Stata将所有缺失值标记为1
,而不是将其保留为0
。
之所以发生这种情况,是因为Stata将缺失值视为大正值。因此,当您为height: 135px;
width: 100%;
.headerContainer{
text-align: right;
width: 100%;
height: 100%;
.navContainer{
width: 50%;
height: 100%;
text-align: center;
display: inline-block;
margin-right: calc(25% - (20% + 135px));
h1{
color: #3D3B30;
font: {
size: 40px;
weight: 600;
}
text-transform: uppercase;
display: inline-block;
}
h1:nth-of-type(2){
margin: 0 90px 0 90px;
}
}
.logincontainer{
display: inline-grid;
grid-template-columns: auto 150px;
width: 20%;
height: 100%;
margin-right: 135px;
.loggain{
vertical-align: middle;
display: inline-block;
h1{
color: #899878;
display: inline-block;
}}
.registrera{
vertical-align: middle;
height: 45px;
display: inline-block;
background-color: #3D3B30;
border-radius: 50px;
h1{
color: #899878;
}}}}}```
的所有值(包括缺失值)请求变量type
时,其变量1
设置为等于pax > 100
。
您可以通过明确表示您不希望将缺失的值替换为1
来避免这种情况:
generate type = 0
replace type = 1 if pax > 100 & pax != .
,
另一种解决方案是使用missing()
函数:
clear
input pax
20
30
40
100
110
130
150
.
.
.
end
generate type = pax > 100 & !missing(pax)
list
+------------+
| pax type |
|------------|
1. | 20 0 |
2. | 30 0 |
3. | 40 0 |
4. | 100 0 |
5. | 110 1 |
|------------|
6. | 130 1 |
7. | 150 1 |
8. | . 0 |
9. | . 0 |
10. | . 0 |
+------------+
请注意在函数之前使用!
,它告诉Stata将重点放在非缺失值上。