Good evening dear stata community,
I am currently using STATA 15 and have run into a problem that I cannot find the solution for myself.
Since this is my first time posting into statalist, please excuse my lack of formatting.
I am trying to prepare my dataset for a survival time analysis. To do that, I have to clone new variables from already existing ones, drop certain missing values (while keeping others) and then generate the duration and censor variables from those.
An example of an already existing variable would be this:
. to create my new variable, I used the following code:
meaning that I drop the undesired missing observations before replacing them with the missing observations that
I do want to keep.
The code is written this way because Stata kept deleting all of my observations if I typed it as
... so far this is the only working way that allows me to only keep the missing values I truly need for my analysis.
I have done this exact procedure on a bunch of variables. However, once I press execute other variables that could previously be displayed via fre or tab won't show up now, as it is the case for my education variable.
My education variable (when using fre right after loading the dataset) will look like this:
... However, after I run execute, it will now only be displayed as:
meaning that I can no longer work with it.
If anyone of you knows why this is the case, I will be very grateful for your help.
Thank you so much and have a good evening. Sorry again for the bad formatting - absolute newby here.
I am currently using STATA 15 and have run into a problem that I cannot find the solution for myself.
Since this is my first time posting into statalist, please excuse my lack of formatting.
I am trying to prepare my dataset for a survival time analysis. To do that, I have to clone new variables from already existing ones, drop certain missing values (while keeping others) and then generate the duration and censor variables from those.
An example of an already existing variable would be this:
PHP Code:
fre df05a
df05a -- MARRIED: YEAR OF WEDDING, MARRIAGE 1
----------------------------------------------------------------------------
| Freq. Percent Valid Cum.
-------------------------------+--------------------------------------------
Valid -10 NAP: SCREENED OUT | 9566 14.03 14.03 14.03
-9 NO ANSWER | 204 0.30 0.30 14.33
-7 REFUSED | 14 0.02 0.02 14.35
-1 NOT AVAILABLE | 43375 63.64 63.64 77.99
1918 | 1 0.00 0.00 77.99
1921 | 2 0.00 0.00 77.99
1922 | 1 0.00 0.00 78.00
1923 | 5 0.01 0.01 78.00
1924 | 5 0.01 0.01 78.01
1925 | 9 0.01 0.01 78.02
1926 | 10 0.01 0.01 78.04
1927 | 16 0.02 0.02 78.06
1928 | 12 0.02 0.02 78.08
1929 | 18 0.03 0.03 78.11
1930 | 21 0.03 0.03 78.14
1931 | 28 0.04 0.04 78.18
1932 | 41 0.06 0.06 78.24
1933 | 43 0.06 0.06 78.30
1934 | 55 0.08 0.08 78.38
1935 | 54 0.08 0.08 78.46
: | : : : :
1991 | 75 0.11 0.11 98.82
1992 | 72 0.11 0.11 98.92
1993 | 64 0.09 0.09 99.02
1994 | 63 0.09 0.09 99.11
1995 | 64 0.09 0.09 99.20
1996 | 61 0.09 0.09 99.29
1997 | 71 0.10 0.10 99.40
1998 | 68 0.10 0.10 99.50
1999 | 64 0.09 0.09 99.59
2000 | 42 0.06 0.06 99.65
2001 | 26 0.04 0.04 99.69
2002 | 31 0.05 0.05 99.74
2003 | 22 0.03 0.03 99.77
2004 | 21 0.03 0.03 99.80
2005 | 21 0.03 0.03 99.83
2006 | 19 0.03 0.03 99.86
2007 | 24 0.04 0.04 99.89
2008 | 29 0.04 0.04 99.94
2009 | 27 0.04 0.04 99.98
2010 | 17 0.02 0.02 100.00
Total | 68161 100.00 100.00
----------------------------------------------------------------------------
PHP Code:
clonevar ymar1 = df05a // ymar1 == first year of marriage
replace ymar1 = . if inlist(ymar1, -10, -1)
drop if ymar1 == .
replace ymar1 = . if inlist(ymar1, -7, -9)
fre ymar1
I do want to keep.
The code is written this way because Stata kept deleting all of my observations if I typed it as
PHP Code:
clonevar ymar1 = df05a
replace ymar1 = . if inlist(ymar1, -7,-9)
drop if ymar1 == -10 | -1
I have done this exact procedure on a bunch of variables. However, once I press execute other variables that could previously be displayed via fre or tab won't show up now, as it is the case for my education variable.
My education variable (when using fre right after loading the dataset) will look like this:
PHP Code:
. fre educy
educy -- YEARS OF SCHOOLING
---------------------------------------------------------------------------
| Freq. Percent Valid Cum.
------------------------------+--------------------------------------------
Valid -10 NAP: SCREENED OUT | 73 0.11 0.11 0.11
-9 NO ANSWER | 551 0.81 0.81 0.92
-8 DO NOT KNOW | 1 0.00 0.00 0.92
-1 NOT AVAILABLE | 58504 85.83 85.83 86.75
4 | 1 0.00 0.00 86.75
5 | 16 0.02 0.02 86.77
6 | 40 0.06 0.06 86.83
7 | 130 0.19 0.19 87.02
8 | 3038 4.46 4.46 91.48
9 | 997 1.46 1.46 92.94
10 | 2252 3.30 3.30 96.25
11 | 407 0.60 0.60 96.84
12 | 490 0.72 0.72 97.56
13 | 518 0.76 0.76 98.32
14 | 190 0.28 0.28 98.60
15 | 181 0.27 0.27 98.87
16 | 213 0.31 0.31 99.18
17 | 207 0.30 0.30 99.48
18 | 148 0.22 0.22 99.70
19 | 82 0.12 0.12 99.82
20 | 75 0.11 0.11 99.93
21 | 19 0.03 0.03 99.96
22 | 12 0.02 0.02 99.98
23 | 9 0.01 0.01 99.99
24 | 4 0.01 0.01 100.00
25 | 3 0.00 0.00 100.00
Total | 68161 100.00 100.00
---------------------------------------------------------------------------
PHP Code:
. fre educy
educy -- YEARS OF SCHOOLING
----------------------------------------------------------------------
| Freq. Percent Valid Cum.
-------------------------+--------------------------------------------
Valid -1 NOT AVAILABLE | 101 100.00 100.00 100.00
----------------------------------------------------------------------
If anyone of you knows why this is the case, I will be very grateful for your help.
Thank you so much and have a good evening. Sorry again for the bad formatting - absolute newby here.
Comment