Here's my data set in a .csv file: ("ins3.csv"): https://www.dropbox.com/s/000rcyo4oo7o4n8/ins3.csv?dl=0 (you may close the splash screen without signing up for anything, and download the file by clicking the button with the "downwards pointing arrow" in the top-middle-right of the screen).
In plain English, I want
1) all blank cells (in variable "ins3") to be converted to numerical zero (0)
2) The value 2 to be recoded to numerical zero (0)
3) The value 9 to be dropped from the dataset
Here's my .do file:
----------------------------------------------------------------------------------------
At the start, my `tab ins3` command produces:
At the end my `tab ins3` command produces:
What I want my `tab ins3` command to produce at the end is:
----------------------------------------------------------------------------------------
My Question: Why doesn't my code work? And if you can share a working alternative please do.
Thanks.
In plain English, I want
1) all blank cells (in variable "ins3") to be converted to numerical zero (0)
2) The value 2 to be recoded to numerical zero (0)
3) The value 9 to be dropped from the dataset
Here's my .do file:
Code:
import delimited ins3.csv, varnames(1) tab ins3 replace ins3="0" if trim(ins3)=="" /* initially, ins3 is encoded as string */ tab ins3 encode ins3, gen(ins3_r) /* convert from string to numerical (long) */ tab ins3_r recast byte ins3_r /* changing long to byte, may not be necessary */ drop if ins3_r == 9 /* doesn't work */ tab ins3_r recode ins3_r 1=1 2=0 0=0, gen(ins3_r2) /* doesn't work */ tab ins3_r2
At the start, my `tab ins3` command produces:
Code:
ins3 | Freq. Percent Cum. ------------+----------------------------------- | 93 88.57 88.57 1 | 8 7.62 96.19 2 | 3 2.86 99.05 9 | 1 0.95 100.00 ------------+----------------------------------- Total | 105 100.00
At the end my `tab ins3` command produces:
Code:
RECODE of | ins3_r | Freq. Percent Cum. ------------+----------------------------------- 0 | 8 7.62 7.62 1 | 93 88.57 96.19 3 | 3 2.86 99.05 4 | 1 0.95 100.00 ------------+----------------------------------- Total | 105 100.00
What I want my `tab ins3` command to produce at the end is:
Code:
ins3 | Freq. Percent Cum. ------------+----------------------------------- 0 | 96 91.43 91.43 1 | 8 8.57 100.00 ------------+----------------------------------- Total | 105 100.00
My Question: Why doesn't my code work? And if you can share a working alternative please do.
Thanks.
Comment