compute incorrect standard errors. Create a local macro variable ver: %let ver = 7; version = &ver.; Technically, SAS macro variables begin with an ampersand ( & ) and end with a period ( . ). It's good practice to end your macro variables with a period. local ver = 7 gen version = `ver' Notice that to evaluate the local macro variable ver a left quote ( `&nsp;) is used and then a right quote ( '&nsp;). The left quote is located on your keyboard next to the ( ! 1&nsp;) key. list in 1/10 if stores < 20 // the order of if and in does not matter: list if stores < 20 in 1/10 Both will first subset the data to the first 10 observations and then attempt to subset the data based on the condition \if stores < 20\So, a hack way of doing the same in Stata is to use the sum() function. Since sum() creates a running sum, you have to repeat the condition outside the sum() to subset the data to that condition to list the first 10 observations. The sum() function adds up the true conditions because true conditions evaluate to 1 (one) and false evaluate to 0 (zero). list if sum((stores < 20)) <= 10 & stores < 20 So you have to repeat the condition to subset the dataset to just those observations before starting the running sum. If the condition is long you could mess up typing it twice so put it in a local macro variable: local cond stores < 20 list if sum((`cond')) <= 10 & `cond' This is what the Stata command ifwins does. There is no built-in Stata command to do this, but the contract command can be used like so: preserve contract region product stores , /// freq(frequency) /// percent(percentage) /// cfreq(cumulative_freq) /// cpercent(cumulative_pct) list restore Print a subset of observations when a condition is true just to see examples (not all situations) where the condition exists in your data: /** WHERE subsets the data * * before OBS subsets the data */ proc print data= sashelp.shoes (where=(stores < 20) obs = 10); run; The above code lists the first 10 observations where (stores < 20). Get a frequency count for each combination of a set of multiple categorical variables: ** example of a 3-way table **; proc freq data= sashelp.shoes; tables region * product * stores / list; run;
来源:李琦
| 分享(378) | 浏览(1125)
源地址: http://blog.renren.com/GetEntry.do?id=725558273&owner=240755041