How do I edit files in Stata? - stata

I'm using Stata 11 on OSX, new to Stata. Someone has sent me a .do file and I want to amend it and run it.
If I open the file in Stata (using File > Open), I see the file appear like this:
I can click on text, but I don't seem to be able to edit or select it. It's almost like an image rather than a text file.
So, um, how do I edit the text?
All of my Googling suggests I need to use the "do-file editor" - I'm not sure if this is it, and if so, how I set it to edit mode!

Open a new .do file (ctrl+9). Then in that go file>open and open the .do file in the editor. That should do the trick.

Related

SAS Enterprise Guide - How can I download a ZIP file from a website, extract its contents and run it?

I would like to have a task to download a continuously updated .ZIP data file from a specific website, extract its contents and run the file inside.
I am looking for a program code that performs these tasks and, so to speak, if the data on the website is updated, then my data file is also updated with it.
How can I do it?
Please help!
SAS Enterprise Guide 8.2
I didn't find a solution for it.
Read Chris method here for reading a zip file using filename statement: https://blogs.sas.com/content/sasdummy/2014/01/29/using-filename-zip/
Chris is the community director at SAS (something like that). A zip file will be locked on an update. Check the file date and store the date somewhere so you can see if it changed.
There are lots of ways to approach your problem and I dont know your constraints. Start with Chris' post and work from there.
You could download the zip using proc http
This macro will let you unzip it: https://core.sasjs.io/mp__unzip_8sas.html
And this macro will give you the recursive directory contents: https://core.sasjs.io/mp__tree_8sas.html

I accidentally saved an rmarkdown file as .html, is there a way back?

As the question says, I had opened a new .Rmd file and did all my work in it without saving it. Then when I wanted to knit it to HTML, RStudio prompted me to first save the rmarkdown file. I didn't fully realize and saved it with .HTML as extension instead of .Rmd. Now the file is all screwed up and I cannot find a way back.
Does anyone have a solution for this to recover my work or will I have to do it over again?

how to resolve this Error: "physical file does not exist"

I couldn't resolve this error where I'm specifying a path to a file. But it seems that the compiler cannot recognize it.
Please help
If SAS says the file doesn't exist then it is not there. Not surprising as that is a really strange name for a file.
Why would you name a file xlsx? That is the extension that Excel uses for workbooks. If it actually is an Excel workbook then why would you try to read it as if it was a simple text file?
Also note that it looks like your file explorer window is not showing you the full filename. None of the files in your picture have the extension part of the filename displayed. What is the full name for that file? Either turn on the display of the extension or use properties to see the real filename.
You cannot access an Excel file that way anyway, so this is using the wrong approach entirely. INFILE is for reading in text type files, not for reading in an Excel file. Assuming you're trying to import your data, this is what you're likely looking to do this:
proc import out=want datafile='c:\users\pi\Documents\xlsx.xlsx' dbms=xlsx replace; run;
PLEASE do not post code and log as images in the future. It makes it harder to help you and answer your question when we first have to type out your code or data.

How to open a .dat file (ASCII)?

I tried to open a .dat file using Stata, and it actually opened, but the data set was a complete mess. I took the file from NBER (CPS data)...
click on the A icon of the year 1964 March.
I tried the regular Stata procedure for .dat files: File->Import->ASKII data created by spreadsheet (delimiter " ") as recommended in Stata manual for .dat files.
But it is still not working. Are there any other ways to open .dat file? Can I convert it to .csv somehow?
(All the data files are ASCII files compressed with the Unix compress command.)
There is a Java app to get you the data from CPS, DataFerrett This app lets you get CPS and other data sets. But it is not very efficient.
I can show you an example how to open one of them yourself (you can use it for any years in the interval 1989 till 2012).
Download the .dat file
Save it in a Desktop folder (C:\Users\Owner...)
Download corresponding .do and .dct files from here
Save them in the same folder
Open the .dat file just the way you open it in your question in Stata
Save it as a Stata .dta file in the same folder (C:\Users\Owner...)
Open the .do file (using Notepad++) that is in your (C:\Users\Owner...) folder
At the very beginning you will see the author presctibes local variables for the paths of .dta, .dat and .dct files. Change the paths so that they point to the saved .dta, .dat and .dct files in your folder (C:\Users\Owner...) on your Desktop
Reopen Stata, and run the .do file from your folder (C:\Users\Owner...)
Done! Save the .dta file
Now, for the years 1962 to 1988, you can do the same procedure (10 steps) as I explained above, but unfortunately NBER does not provide the .do and .dct files. It means that you have to write them yourself. Take one of the available .do and .dct files from any of the years (1989 - 2012) as a benchmark, and write your own .do and .dct files. You will have to make corrections so that the new .do and .dct files are consistent with the corresponding .pdf documentation for each year. I know it is very tideous, but this is the only way you can handle it.
We need more information.
".dat" is not an extension that is special so far as Stata is concerned. Perhaps you meant .dta.
Even if so, what file was it, what command did you use and what was wrong?
The page you linked to leads to numerous files. We have not a hope of guessing which you mean.
Spelling is "Stata".
might not save you from spending days digging into that data but here's some ideas:
the file contains 2 completely different kinds of lines. this might be the reason why you can't import them. you can see this by opening the unzipped file in a text editor. you have to find out what that means.
what do you want to obtain from this file? according to the pdf it contains 85 different values per record. do you need them all? if you're only interested in a few values you could extract them in a unix shell.

C++: Text File's Extensions? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When i use text files for input and output using fstream filestream, the file extension used is .txt
I have seen people use instead of .txt:
They use .DAT and still they open it in a text editor as if it were a text file.
So is DAT a text file extension and are there what are all the extensions i can use with text files.?
The short answer: text files can have any extension you want, including NO extension. You can take somefile.txt and rename it to somefile.XYZPDQ if you feel like it. It will still be a text file.
That's from a pure C++ language perspective. At the operating system level, a file extension may be associated with a certain program type (you might have .mp4 videos open in a video player, for example). But you can still call any text file anything you want. Nothing stops you from doing this.
An extension is just part of file name. There is no difference what extension you use DAT or TXT. I mean, extensions help to people to recognize the file type, only to people.
You can use any extension, but :
using .txt, you usually give a hint that the file can be opened in a text editor (like vim or notepad) and will be readable by humans
using .dat, you usually give a hint that the file is binary and cannot be opened with a text editor. One should use a special program (maybe yours ;) or an hexadecimal binary editor, and its content will not be easily readable or modifiable.
another common extension you may use is .csv for comma-separated-values files (even when not using comma but tabs or anything), than can be opened either in a text editor or in a spreadsheet app like openoffice of excel.
windows users often use .ini extension to hint that the file is a text file (viewable in a text editor) containing some key/value paramters like ConfirmBeforeExit=true. By extension, it is used for any text file containing parameters.
another one is .log, hinting that the file is a text file, containing the log of execution of something. A linux user will then immediately do a tail -f foo.log while the app is running to look for problems.
By the way, using upper case extensions like TXT or DAT is a reminder of old DOS time and is now considered bad style. Just use lower case.
You can use any extension, because it does not matter. The .dat extension is usually used for binary data, so it may not be obvious for users of your program that it is in fact an editable text file.
The extension has no effect on what type of data you can put in the file. For example you can use TXT, DAT, and even(not recommended) EXE. It's best to stick with one extension. If something is meant to be read by a human, I would use TXT, but DAT or the like to indicate otherwise.